The Tkinter Entry widget is a single-line text box for user input such as a name, a number or a password. Create it with tk.Entry(parent), read the text with get(), change it with delete() and insert(), and control what users can type with validatecommand. This guide covers each of these, plus placeholder text, password fields, the Enter key, ttk.Entry and the errors beginners run into.
Every example is a complete program, tested with Python 3.12.5 with Tk 8.6.13 on Windows 11. The screenshots are the real windows. For the full reference, see the tkinter.ttk documentation.
Tkinter Entry example
import tkinter as tk
root = tk.Tk()
root.title("Entry")
root.geometry("320x150")
tk.Label(root, text="Your name:").pack(pady=(15, 2))
name_entry = tk.Entry(root, width=30)
name_entry.pack()
greeting = tk.Label(root, text="")
greeting.pack(pady=5)
def say_hello():
name = name_entry.get() # the text in the Entry, always a str
greeting.config(text=f"Hello, {name}!")
tk.Button(root, text="Greet", command=say_hello).pack()
root.mainloop()

get().get() always returns a string. It’s only useful inside a function that runs later (a button click or a key press), because when the program starts the Entry is still empty. More ways to read the text: get text from a Tkinter Entry.
Entry options: width, font, colour and state
import tkinter as tk
root = tk.Tk()
root.title("Entry options")
root.configure(padx=20, pady=15)
examples = [
("width=12", dict(width=12)),
("font", dict(font=("Segoe UI", 14))),
("justify='center'", dict(justify="center")),
("bg / fg", dict(bg="#fff8dc", fg="#1f4e79")),
("relief='solid'", dict(relief="solid", bd=1)),
("highlight border", dict(highlightthickness=2, highlightcolor="#306998", highlightbackground="#9ab")),
("state='disabled'", dict(state="disabled")),
("state='readonly'", dict(state="readonly")),
]
for row, (label, options) in enumerate(examples):
tk.Label(root, text=label, anchor="w", width=16).grid(row=row, column=0, sticky="w", pady=3)
entry = tk.Entry(root, **options)
entry.grid(row=row, column=1, sticky="w")
if options.get("state"): # insert() is ignored while disabled/readonly
entry.config(state="normal")
entry.insert(0, "Python Guides")
entry.config(state=options["state"])
else:
entry.insert(0, "Python Guides")
root.mainloop()

| Option | What it does |
|---|---|
width | Width in characters (not pixels). Default 20. |
font | For example ("Segoe UI", 14). A bigger font also makes the Entry taller; Entry has no height option. |
justify | "left", "center" or "right" (handy for numbers). |
bg, fg | Background and text colour. insertbackground sets the cursor colour. |
relief, bd | Border style ("flat", "solid", "sunken"…) and width. |
highlightthickness, highlightcolor | A focus ring that changes colour when the Entry has the cursor. |
show | Character to display instead of the text, e.g. "*" for passwords. |
state | "normal", "disabled" (greyed out, can’t select) or "readonly" (can select and copy, can’t edit). |
textvariable | A StringVar linked to the text. |
validate, validatecommand | Check each change before it happens (see below). |
Get the Entry value (and convert it to a number)
To use the input as a number, convert it and handle the case where it isn’t one:
import tkinter as tk
root = tk.Tk()
age_entry = tk.Entry(root)
age_entry.pack()
def read_age():
text = age_entry.get().strip()
try:
return int(text)
except ValueError:
print(f"Not a whole number: {text!r}")
return None
for typed in ["42", " 7 ", "", "4.5"]:
age_entry.delete(0, tk.END)
age_entry.insert(0, typed)
print(repr(age_entry.get()), "->", read_age())
root.destroy()
Output:
'42' -> 42
' 7 ' -> 7
Not a whole number: ''
'' -> None
Not a whole number: '4.5'
'4.5' -> None
strip() removes spaces users type by accident. For a float, use float(text) the same way.
Set, clear and default value
There’s no set() method on an Entry. Clear the text with delete(0, tk.END) and add new text with insert(), or link a StringVar with textvariable and call set() on that:
import tkinter as tk
root = tk.Tk()
# 1) insert / delete
city = tk.Entry(root)
city.insert(0, "London") # default value
print("start:", city.get())
city.delete(0, tk.END) # clear it
city.insert(0, "New York") # set new text
print("after set:", city.get())
city.insert(tk.END, ", USA") # append
print("after append:", city.get())
# 2) textvariable: set and get through a StringVar
city_var = tk.StringVar(value="Paris")
city2 = tk.Entry(root, textvariable=city_var)
print("StringVar default:", city2.get())
city_var.set("Tokyo")
print("after city_var.set():", city2.get())
root.destroy()
Output:
start: London
after set: New York
after append: New York, USA
StringVar default: Paris
after city_var.set(): Tokyo
Inserting text right after creating the Entry gives it a default value. More options (including a default that disappears on click) in Tkinter Entry default value.
Placeholder text
Tkinter has no placeholder option. This small subclass shows grey hint text while the Entry is empty, clears it when the user clicks in, and makes get() return an empty string while the hint is showing:
import tkinter as tk
class PlaceholderEntry(tk.Entry):
"""An Entry that shows grey hint text while it is empty and not focused."""
def __init__(self, master, placeholder, **kwargs):
super().__init__(master, **kwargs)
self.placeholder = placeholder
self.normal_fg = self.cget("fg")
self.bind("<FocusIn>", self._clear)
self.bind("<FocusOut>", self._show)
self._show()
def _show(self, event=None):
if not super().get():
self.insert(0, self.placeholder)
self.config(fg="grey")
def _clear(self, event=None):
if self.cget("fg") == "grey":
self.delete(0, tk.END)
self.config(fg=self.normal_fg)
def get(self):
"""The real value: an empty string while the placeholder is showing."""
return "" if self.cget("fg") == "grey" else super().get()
root = tk.Tk()
root.title("Sign up")
root.configure(padx=20, pady=15)
email = PlaceholderEntry(root, "you@example.com", width=30)
email.pack(pady=4)
phone = PlaceholderEntry(root, "Phone number", width=30)
phone.pack(pady=4)
tk.Button(root, text="Submit", command=lambda: print(repr(email.get()), repr(phone.get()))).pack(pady=6)
root.mainloop()

Before and after filling in the phone number, get() returns:
'' ''
'' '555-0142'
Password field: show=”*”
import tkinter as tk
root = tk.Tk()
root.title("Password")
root.configure(padx=20, pady=15)
tk.Label(root, text="Password:").grid(row=0, column=0, sticky="w")
password = tk.Entry(root, show="*", width=24) # every character is displayed as *
password.grid(row=0, column=1, padx=6)
visible = tk.BooleanVar(value=False)
def toggle():
password.config(show="" if visible.get() else "*")
tk.Checkbutton(root, text="Show password", variable=visible, command=toggle).grid(
row=1, column=1, sticky="w", pady=4)
root.mainloop()

show="*" hides the characters.
show="" to reveal the password.show only changes what is displayed:
get() returns the real text: Sup3rSecret!
Run a function when the user presses Enter
An Entry has no command option:
import tkinter as tk
root = tk.Tk()
entry = tk.Entry(root, command=lambda: print("Enter"))
_tkinter.TclError: unknown option "-command"
Use bind("<Return>", ...) instead. The bound function receives an event argument, so give it a default of None and the same function works for a button too:
import tkinter as tk
root = tk.Tk()
root.title("Search")
root.configure(padx=20, pady=15)
search = tk.Entry(root, width=30)
search.pack()
search.focus_set() # the cursor starts in the Entry
result = tk.Label(root, text="Type and press Enter")
result.pack(pady=6)
def run_search(event=None): # event is passed by bind(), not by the button
result.config(text=f"Searching for: {search.get()}")
search.bind("<Return>", run_search) # Enter key on the main keyboard
search.bind("<KP_Enter>", run_search) # Enter key on the number pad
tk.Button(root, text="Search", command=run_search).pack()
root.mainloop()

Pressing Enter in the test gives:
Searching for: tkinter entry