I am creating an application and I want to use the entered values in the GUI Entry widget.
How do I get the entered input from a Tkinter Entry widget?
root = Tk()
...
entry = Entry(root)
entry.pack()
root.mainloop()
I am creating an application and I want to use the entered values in the GUI Entry widget.
How do I get the entered input from a Tkinter Entry widget?
root = Tk()
...
entry = Entry(root)
entry.pack()
root.mainloop()
You need to do two things: keep a reference to the widget, and then use the get()
method to get the string.
Here's an example:
self.entry = Entry(...)
...
print("the text is", self.entry.get())
First declare a variable of required type. For example an integer:
var = IntVar()
Then:
entry = Entry(root, textvariable=var)
entry.pack()
user_input = var.get()
root.mainloop()
Hope this helps.
© 2022 - 2024 — McMap. All rights reserved.