How can I take a value a user inputs into a tkinter Entry widget
and store it as a float? I have created a tkinter Entry widget
so the user can input a decimal value:
from tkinter import *
window = Tk()
a = Entry()
a.pack()
number = float(a.get())
window.mainloop()
I get an error from number = float(a.get())
that states: ValueError: could not convert string to float: ''
. Is this because the tkinter Entry widget is empty without further configurations?
Edit: found solution: bind the tkinter Entry widget
using tkinter.Entry.bind()
. I set the parameters of bind()
to <Return>
followed by a comma and a lambda function
.