简体   繁体   中英

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.

Every time I try to fix it I get the same ValueError

I've tried using IntVar, taking multiple variables and stuff, but I couldn't get to a conclusion. 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


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: ''

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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