14

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()
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    possible duplicate of [Tkinter: get Entry content with get()](http://stackoverflow.com/questions/10727131/tkinter-get-entry-content-with-get) – nbro Mar 09 '15 at 19:45
  • @Rinzler ? This question is older then that one. And why mark as a duplicate right now? – Zizouz212 Apr 12 '15 at 20:23
  • @Zizouz212 The age of questions [does not matter, per official policy](https://meta.stackoverflow.com/questions/251938) when closing duplicates. That said, this is not a duplicate, although the two questions have an important relationship. This one is a how-to about getting the information generally; the other is a debugging question about timing and managing events (i.e., *when* to get the information). – Karl Knechtel Apr 10 '23 at 10:02

2 Answers2

30

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())
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
7

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.

Community
  • 1
  • 1