Get contents of a Tkinter Entry widget

user1786283 picture user1786283 · Mar 22, 2012 · Viewed 50.1k times · Source

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()

Answer

Bryan Oakley picture Bryan Oakley · Apr 5, 2012

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())