Python's built-in GUI toolkit โ zero install, huge tutorial base, perfect for learning and small tools.
Tkinter ("Tk interface") is Python's de-facto standard GUI package. It
is a thin object-oriented layer over Tcl/Tk, a mature cross-platform
toolkit dating to the early 1990s. When you call tk.Button(...), Python forwards
the request to an embedded Tcl interpreter, which drives the actual Tk widgets on screen.
This bridge is invisible in daily use but explains why some error messages mention Tcl.
Because Tkinter ships with the official CPython installer on Windows and macOS, it is
almost always available with zero setup โ which is why nearly every Python GUI tutorial
starts here. On Linux, the python3-tk package is sometimes a separate install.
Every Tkinter app revolves around four ideas:
Tk() instance owns the widget tree.pack(), grid(), or place() position widgets (never mix pack and grid in the same parent).mainloop() blocks and dispatches user events to your callbacks.Legacy widgets (tk.Button, tk.Label) look dated. Prefer
tkinter.ttk ("themed Tk") for OS-aware styling:
ttk.Button, ttk.Combobox, ttk.Treeview,
ttk.Notebook (tabs), ttk.Progressbar. Use classic
tk.Text and tk.Canvas when ttk has no equivalent.
| Widget | Module | Purpose |
|---|---|---|
ttk.Label | ttk | Static text or image |
ttk.Entry | ttk | Single-line text input |
tk.Text | tk | Multi-line editable text |
ttk.Combobox | ttk | Dropdown selection |
ttk.Treeview | ttk | Tables and tree lists |
ttk.Notebook | ttk | Tabbed panels |
tk.Canvas | tk | Custom drawing, charts, games |
ttk.Scale | ttk | Slider for numeric values |
ttk.Frame | ttk | Container for grouping widgets |
# Already bundled with Python on Windows/macOS.
# On Debian/Ubuntu Linux:
sudo apt install python3-tk
# Verify โ opens a small test window:
python -m tkinter
# In code:
python -c "import tkinter; print(tkinter.TkVersion)"
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Tkinter demo")
ttk.Label(root, text="Your name:").pack(padx=10, pady=6)
entry = ttk.Entry(root)
entry.pack(padx=10)
def greet():
ttk.Label(root, text=f"Hello, {entry.get()}!").pack()
ttk.Button(root, text="Greet", command=greet).pack(pady=8)
root.mainloop()
Use grid() with columnconfigure(weight=1) so inputs stretch when the window resizes โ essential for professional-looking forms.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Contact form")
root.columnconfigure(1, weight=1)
fields = ["Name", "Email", "Phone"]
entries = {}
for i, label in enumerate(fields):
ttk.Label(root, text=label).grid(row=i, column=0, sticky="e", padx=8, pady=4)
e = ttk.Entry(root)
e.grid(row=i, column=1, sticky="ew", padx=8)
entries[label] = e
def submit():
data = {k: v.get() for k, v in entries.items()}
print("Saved:", data)
ttk.Button(root, text="Submit", command=submit).grid(row=3, column=1, sticky="e", padx=8, pady=10)
root.mainloop()
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
notebook = ttk.Notebook(root)
notebook.pack(fill="both", expand=True, padx=10, pady=10)
tab1 = ttk.Frame(notebook)
tab2 = ttk.Frame(notebook)
notebook.add(tab1, text="Data")
notebook.add(tab2, text="About")
tree = ttk.Treeview(tab1, columns=("name", "score"), show="headings")
tree.heading("name", text="Name")
tree.heading("score", text="Score")
tree.pack(fill="both", expand=True)
tree.insert("", "end", values=("Alice", 95))
tree.insert("", "end", values=("Bob", 87))
ttk.Label(tab2, text="Tkinter tabbed demo").pack(pady=20)
root.mainloop()
StringVar, IntVar, BooleanVar to bind widget state and react to changes with trace_add().mainloop() โ run slow work in a thread and poll results with root.after() (see threading guide).root.minsize(w, h) to prevent layout collapse.messagebox and filedialog from tkinter for standard dialogs instead of building your own.--windowed; tkinter is detected automatically on most setups.Tkinter's simplicity spawned a rich extension ecosystem:
tk.Label via ImageTk.PhotoImageYou are learning GUIs, building an internal tool, a small utility, or want zero dependencies. Avoid it when you need mobile deployment, complex data grids, or a polished consumer-facing product without extra styling layers.
Useful guides and tools (from webpage_links.xlsx).