I am trying to make a row of Entry widgets that add numeric values up and input the total into the left-most column. I am able to make the code function, but it is throwing an exception anytime I try and use the get() method on a variable class. Here is an example:
from tkinter import *
root = Tk()
ent1 = IntVar()
ent2 = IntVar()
ent3 = IntVar()
def callback(*args):
ent1.set(ent2.get() + ent3.get())
frame = Frame(root)
frame.pack()
entry1 = Entry(frame, width=5, textvariable=ent1)
entry2 = Entry(frame, width=5, textvariable=ent2)
entry3 = Entry(frame, width=5, textvariable=ent3)
entry1.pack(side=LEFT)
entry2.pack(side=LEFT)
entry3.pack(side=LEFT)
ent1.trace_add('write', callback)
ent2.trace_add('write', callback)
ent3.trace_add('write', callback)
root.mainloop()
and here is the exception:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Paul Desktop\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 508, in get
return self._tk.getint(value)
_tkinter.TclError: expected integer but got ""
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Paul Desktop\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/Paul Desktop/PycharmProjects/Pathfinder Character Sheet/EntryTest.py", line 15, in callback
ent1.set(ent2.get() + ent3.get())
File "C:\Users\Paul Desktop\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 510, in get
return int(self._tk.getdouble(value))
_tkinter.TclError: expected floating-point number but got ""
I have no clue why this is happening and I could use some assistance in what to do!