【发布时间】:2019-07-08 00:28:06
【问题描述】:
使用 python3.7 和 tkinter 制作 GUI,我从 2 个文本框中获取输入,然后使用数学公式将其导出。
我查看了其他表单并尝试了他们的建议,但找不到解决方法。我在函数内部和外部都尝试过全局,在函数之前设置变量。
def retrieve_input():
global InputValue
global InputValue2
global Delay
InputValue=tasks.get()
InputValue2=proxies.get()
print(InputValue)
print(InputValue2)
Delay=3500/int(InputValue)*int(InputValue2)
print(Delay)
retrieve_input()
Label (window, width=12, text=Delay,bg="white",fg="Pink", font="none 22 bold") .grid(row=5, column=0,sticky=W)
错误:
File ", line 29, in retrieve_input
Delay=3500/int(InputValue)*int(InputValue2)
ValueError: invalid literal for int() with base 10: ''
【问题讨论】:
-
您正在尝试将空字符串转换为 int,如错误所示。检查您的输入。
-
@Carcigenicate 是的,我知道,我只是不知道如何让它不为空,因为我需要等待客户使用它。
-
当文本框被修改(stackoverflow.com/questions/6548837/…)或按下某种提交按钮时,您将调用此函数。
-
答案就在您刚才提出的问题中。您需要等待客户使用教科书。所以在这发生之前不要运行代码。
-
您可以使用
0 if not InputValue else int(InputValue)代替int(InputValue2)(将0替换为您想要的默认值)。
标签: python python-3.x tkinter