How do I get the value from an Entry in tkinter?
Call .get() on the widget, from inside the function that runs when the user clicks. That last part is where nearly every "it returns nothing" question comes from.
import tkinter as tk
root = tk.Tk()
name_entry = tk.Entry(root)
name_entry.pack()
def greet():
name = name_entry.get() # read it *now*, not earlier
print("Hello", name)
tk.Button(root, text="Greet", command=greet).pack()
root.mainloop() Why yours comes back empty
The usual mistake is reading the value while building the window: name = name_entry.get() sitting next to the widget rather than inside the handler. That runs once, before the user has typed anything, so it captures an empty string forever. .get() has to be called at the moment you need the value.
The same applies to passing it to a command: command=greet(name_entry.get()) calls greet immediately with the empty value and hands its return value to tkinter. Pass the function itself — command=greet — with no parentheses.
The StringVar alternative
A StringVar is a value the widget and your code share. Read it with .get() and write it with .set(), and the field updates on its own. It is the tidier option when several widgets show the same value, or when you want to preset the field.
name_var = tk.StringVar(value="Ada")
name_entry = tk.Entry(root, textvariable=name_var)
name_var.get() # what the user has typed
name_var.set("Grace") # updates the box on screenClearing and presetting the box
Without a variable, an Entry is edited by index. delete takes a start and an end, where "end" means the end of the text — this is also the answer to "how do I clear an entry".
A Text widget uses line.column indices instead, so clearing one is text.delete("1.0", "end").
name_entry.delete(0, "end") # clear it
name_entry.insert(0, "Ada") # then preset itReading it when they press Enter
Binding <Return> on the entry gives you the keyboard path as well as the button. The handler takes an extra event argument, which is the part people forget.
def on_enter(event):
print(name_entry.get())
name_entry.bind("<Return>", on_enter) Doing it without the lookup
Drag an Entry on, tick "Expose a variable" and the export wires a StringVar for you. Buttons get a handler stub with the right signature, and event bindings like <Return> are a dropdown rather than something to look up — so the value is read in the one place it works.
Lay the window out visually and read the generated Python as you go.
Open the tkinter designer →