简体   繁体   English

如何从Tkinter的Entry中获取整数值?

[英]How to get an integer value from Entry in Tkinter?

I've been trying to make a simple program to compare three numbers. 我一直在尝试制作一个简单的程序来比较三个数字。 I just used the START and STOP buttons for the sake of using Tkinter but now I wanted to insert some Entry Boxes to input data instead of the simple IDLE. 我只是为了使用Tkinter而使用了START和STOP按钮,但是现在我想插入一些输入框来输入数据,而不是简单的IDLE。

Every time I try to fix it I get the same ValueError 每次尝试修复它时,我都会得到相同的ValueError

I've tried using IntVar, taking multiple variables and stuff, but I couldn't get to a conclusion. 我已经尝试过使用IntVar,并采用了多个变量和其他方法,但无法得出结论。 I also wouldn't like to use IntVar because my teacher's going to be mad if I use it and I don't know why =P 我也不想使用IntVar,因为如果我使用它,我的老师会生气的,我不知道为什么= P


t1 = tk.Entry(root)

t1.grid(row = 8, column = 0)

t2 = tk.Entry(root)

t2.grid(row = 10, column = 0)

t3 = tk.Entry(root)

t3.grid(row = 12, column = 0)


x = int(t1.get())

y = int(t2.get())

z = int(t3.get())

ERROR: 错误:

Traceback (most recent call last): File "C:/Users/CB Singh/Desktop/Compare01.py", line 25, in x = int(t1.get()) ValueError: invalid literal for int() with base 10: '' 追溯(最近一次通话最近):文件“ C:/ Users / CB Singh / Desktop / Compare01.py”,第25行,在x = int(t1.get())中ValueError:int()以10为底的无效文字:''

text1=tk.IntVar()
t1 = tk.Entry(root,textvariable=text1)
t2 = t1.get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM