How do I get the Entry’s value in tkinter?

Your first problem is that the call to get in entry = E1.get() happens even before your program starts, so clearly entry will point to some empty string.

Your eventual second problem is that the text would anyhow be printed only after the mainloop finishes, i.e. you close the tkinter application.

If you want to print the contents of your Entry widget while your program is running, you need to schedule a callback. For example, you can listen to the pressing of the <Return> key as follows

import Tkinter as tk


def on_change(e):
    print e.widget.get()

root = tk.Tk()

e = tk.Entry(root)
e.pack()    
# Calling on_change when you press the return key
e.bind("<Return>", on_change)  

root.mainloop()

Leave a Comment