Mar-05-2024, 10:05 PM
(This post was last modified: Mar-05-2024, 10:05 PM by deanhystad.)
Quote:Sorry i didnt include a sample as I didnt think it would help as you cant see the problem as such, as it happens when you select the contents of entry and type a new value.Code is useful for a lot of things. It is a very accurate description of the problem. It provides insight into you level of knowledge. It establishes a starting point for future conversations. It is best if you can post code that others can run to see the problem.
import tkinter as tk def check(*args): print(float(txt1.get())) root = tk.Tk() txt1 = tk.StringVar(root, "0") txt1.trace_add("write", check) entr1 = tk.Entry(root, width=10, textvariable=txt1) entr1.pack(padx=50, pady=50) root.mainloop()And then add instructions for how to make the error occur.
Quote:To make the error happen, select the text in the entry and type in a digit. You should get an error like this:
Error:File "..test.py", line 4, in check print(float(txt1.get())) ValueError: could not convert string to float: ''
To answer your question, you get "" because pasting (or typing) in an entry deletes any selected text before entering new text. When there is a selection, the entry gets written twice. You'll see this if you run your example and alternate between typing with or without selecting text in the entry.