[英]How to fix invalid literal for int() with base 10: ''?
Using python3.7 and tkinter to make a GUI, where I grab the input from 2 text boxes, and use a math formula then export it out.使用 python3.7 和 tkinter 制作一个 GUI,我从 2 个文本框中获取输入,然后使用数学公式将其导出。
I've looked through other forms and tried what they suggested and could not find how to fix it.我查看了其他表格并尝试了他们的建议,但找不到解决方法。 I've tried global inside and outside of the function, setting the variable before the function.
我已经尝试在函数内部和外部使用 global,在函数之前设置变量。
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)
Error:错误:
File ", line 29, in retrieve_input
Delay=3500/int(InputValue)*int(InputValue2)
ValueError: invalid literal for int() with base 10: ''
It means that you are passing in an empty string to the int class constructor.这意味着您将空字符串传递给 int 类构造函数。 You are effectively calling
int('')
.您正在有效地调用
int('')
。 It looks like either tasks.get()
or proxies.get()
are returning the empty string.看起来
tasks.get()
或proxies.get()
都返回空字符串。
As for the comment you left:至于你留下的评论:
try:
Delay=3500/int(InputValue)*int(InputValue2)
except ValueError:
pass
#Handle a case in which the input is ''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.