Reputation: 9479
I’m making a little pricing tool in Pythonista. Here’s what I wrote.
# starts actions with go button
def getPrices(mtmPriceUser):
viewSelector = mtmPriceUser.superview
userInput = viewSelector['textview1'].text
userInput = float(userInput)
textLabel1 = v['label1']
discNamesList, discOutcomesdict = creatDiscList(standardDisc, userInput)
# create string of discounts and prices
priceString = createString(discNamesList,discOutcomesDict)
textLabel1.text = priceString
textLabel1.end_editing()
v = ui.load_view()
v.present('sheet')
I get the following error
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/7C463C71-C565-47D8-A1D8-C2D588A974C1/Pythonista3/Documents/Pricing App/UI_Attempt.py", line 79, in getPrices
textLabel1.end_editing()
AttributeError: '_ui.Label' object has no attribute 'end_editing'
Where do I use the end editing method? If I can’t, how else can I get the keyboard to go away after I push the button?
Upvotes: 1
Views: 198
Reputation: 4391
You seem to be calling end_editing()
on a label, which does not have this method.
You need to call the method on the TextField
or TextView
object that was used for data entry.
In your case, this seems to be viewSelector['textview1']
which might be worth storing in a variable for simplicity, like you do with the label.
For example:
text_entry = viewSelector['textview1']
userInput = text_entry.text
# Your other code
text_entry.end_editing()
Upvotes: 0