我有这个 tkinter GUI,我需要从条目中获取值并进行比较。
self.hystInt.get()
是在Entry中的string变量中访问string的方式。 *我必须为每个变量都写这个,所以它最终看起来真的很难看。
if (self.hystInt.get().isdigit() and int(self.hystInt.get()) >= 200 and int(self.hystInt.get()) <= 500):
最佳答案
def validate(num):
try:
return 200 <= int(num) <= 500
except ValueError:
return False
简单就是好!
关于python - 编写此 if 语句的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4072871/