Mar-04-2024, 06:17 PM
Hello,
I have a simple program that takes user input from a tkinter entry widget and then converts the user input to a float for processing.
I am using Stringvar linked to the entry-textvariable and trace_add to monitor when the contents of the entry widget change to then call the function for processing
That is all working when a correct entry is passed, the issue I am seeing however is when the entry widget gains focus and the current contents are selected.
If I then type a new entry, effectively overwriting the contents of the entry widget, a call to the trace is made twice.
This first time containing '' which then gives the error ValueError: could not convert string to float: ''
A second call is then made with the values I have typed in the entry box and it all works fine.
I cannot figure out why Stringvar is set to '' when I enter a value into the entry widget.
Can anyone help me understand why this is happening and how to fix it?
Thanks.
I have a simple program that takes user input from a tkinter entry widget and then converts the user input to a float for processing.
I am using Stringvar linked to the entry-textvariable and trace_add to monitor when the contents of the entry widget change to then call the function for processing
That is all working when a correct entry is passed, the issue I am seeing however is when the entry widget gains focus and the current contents are selected.
If I then type a new entry, effectively overwriting the contents of the entry widget, a call to the trace is made twice.
This first time containing '' which then gives the error ValueError: could not convert string to float: ''
A second call is then made with the values I have typed in the entry box and it all works fine.
I cannot figure out why Stringvar is set to '' when I enter a value into the entry widget.
Can anyone help me understand why this is happening and how to fix it?
Thanks.