首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Pythonista中,我应该把end_editing()放在哪里?

在Pythonista中,我应该把end_editing()放在哪里?
EN

Stack Overflow用户
提问于 2019-07-26 02:29:02
回答 1查看 112关注 0票数 1

我正在用Pythonista做一个小的定价工具。这是我写的。

代码语言:javascript
复制
# 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')

我得到以下错误

代码语言:javascript
复制
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'

在哪里使用end编辑方法?如果我不能,我怎么能在我按下按钮后让键盘消失呢?

EN

回答 1

Stack Overflow用户

发布于 2019-11-13 05:29:11

您似乎是在没有此方法的label上调用end_editing()

您需要在用于数据输入的TextFieldTextView对象上调用该方法。

在您的示例中,这似乎是viewSelector['textview1'],为了简单起见,它可能值得存储在一个变量中,就像您对标签所做的那样。

例如:

代码语言:javascript
复制
text_entry = viewSelector['textview1']
userInput = text_entry.text
# Your other code
text_entry.end_editing()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57208179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档