【问题标题】:Where do I put end_editing() in Pythonista?我在 Pythonista 中将 end_editing() 放在哪里?
【发布时间】:2019-11-13 05:29:10
【问题描述】:

我正在 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'

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

【问题讨论】:

    标签: pythonista


    【解决方案1】:

    你似乎在一个标签上调用end_editing(),它没有这个方法。

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

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

    例如:

    text_entry = viewSelector['textview1']
    userInput = text_entry.text
    # Your other code
    text_entry.end_editing()
    

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2011-08-29
      • 1970-01-01
      相关资源
      最近更新 更多