1

我正在 Pythonista 中制作一个小定价工具。这是我写的。

# 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')

我收到以下错误

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'

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

4

1 回答 1

0

您似乎正在调用end_editing()一个没有此方法的标签。

您需要调用用于数据输入的TextFieldor对象的方法。TextView

在您的情况下,这似乎viewSelector['textview1']值得为简单起见存储在变量中,就像您对标签所做的那样。

例如:

text_entry = viewSelector['textview1']
userInput = text_entry.text
# Your other code
text_entry.end_editing()
于 2019-11-12T21:29:10.623 回答