python - Getting "ValueError: invalid literal for int" when trying to make a GUI with tKinter -


i have worked on bit , try not seem fix problem. relatively inexperienced nuances of programing language. appreciate tips.

from tkinter import *      root = tk()      lbltitle = label(root, text="adding program")     lbltitle.grid(row=0, column=3)  lbllabelinput = label(root, text="input first number") lbllabelinput.grid(row=1, column=0)  entnum1 = entry(root, text=1) entnum1.grid(row=1, column=1)  lbllabelinput2 = label(root, text="input second number") lbllabelinput2.grid(row=1, column=2)  entnum2 = entry(root, text=1) entnum2.grid(row=1, column=3)   def callback():     ent1 = entnum1.get()     ent2 = entnum2.get()     if ent1 != 0 , ent2 != 0:                 result = int(ent1) + int(ent2)                 lblresult = label(root, text=str(result))                 lblresult.grid(row=3)  btnadd = button(root, text="add", command=callback()) btnadd.grid(row=2)  root = mainloop() 

here traceback

traceback (most recent call last):   file "/users/matt9878/google drive/addingprogram/addingprogram.py", line 31, in <module>     btnadd = button(root, text="add", command=callback())   file "/users/matt9878/google drive/addingprogram/addingprogram.py", line 27, in callback     result = int(ent1) + int(ent2) valueerror: invalid literal int() base 10: '' 

btnadd = button(root, text="add", command=callback()) 

callback should not have parentheses here. makes function execute instead of waiting button pressed.

btnadd = button(root, text="add", command=callback) 

additionally, if ent1 != 0 , ent2 != 0 going evaluate true because ent1 , ent2 strings, , string never equal zero. perhaps meant if ent1 != '' , ent2 != '':, or if ent1 , ent2:


additionally, should delete text attributes entry objects. don't know they're supposed since don't see listed in documentation, looks long they're both equal one, typing in 1 entry cause same text appear in other entry.



Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -