I have been developing with Python / tkinter for a year and up to now found answers to all my questions on stackoverflow - thank you all. So this is my first question for which I have not found the answer... yet: To run some update processes I trace the IntVar textvariable of a Spinbox. The update process retrieves the value of the textvariable with textvariable.get(). All is fine when clicking up/down arrows or when clicking in the entry box and changing one digit at a time. But selecting the entire entry (double click for example) and starting to overwrite it gives me the following error:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/Utilisateur/Documents/TAO_Perf/Development/Apps/test/test.py", line 7, in val_update
print(screen_val.get())
File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 537, in get
return int(self._tk.getdouble(value))
_tkinter.TclError: expected floating-point number but got ""
Here is a code snippet to reproduce:
import tkinter as tk
root = tk.Tk()
def val_update(*args):
print(screen_val.get())
screen_val = tk.IntVar()
screen_val.set(10)
tk.Spinbox(root, textvariable=screen_val, from_=1, to=100).pack()
screen_val.trace("w", val_update)
root.mainloop()
What am I doing wrong? What seems to happen is that the entry field is cleared and the trace function is called before recording the first keystroke. So the textvariable is empty ("" weird for an IntVar?) when the val_update() trace function is called.
I can just ignore the error and all is fine on the second call of the trace function, but I do lot like to see Traceback's when running my code. Any hints on how to avoid that error? Thank you All