【发布时间】:2018-04-06 15:54:07
【问题描述】:
在 iOS 的 pythonista 应用程序中,当我按下按钮时,我试图检查我的 ui 中的文本字段是否有任何数字。当我在字符串上使用相同的代码时,它可以工作。当我在按钮操作中使用文本字段的代码时,它不起作用。请帮忙?这是我的代码:
import ui
import console
def contains_digits(d):
for char in d:
if char.isdigit():
return True
return False
test='test3'
print(contains_digits(test)) #this works - it prints TRUE!
#below always prints failed even though it should print whatever is in the textfield?!
def button_pushed(sender):
if contains_digits(textfield1):
print(textfield1)
print('failed')
v=ui.load_view()
textfield1 = str(v['textfield1'].text)
v.present('fullscreen')
【问题讨论】:
-
你的缩进是否正确?
-
是的 - 抱歉,这就是我在 stackoverflow 中输入错误的地方。会更新。谢谢
标签: python ios pythonista