Tkinter Tutorial
Learn Tkinter step by step: 40 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- Introduction to Tkinter Meet Tkinter, Python's built-in GUI toolkit: what it is, how widgets, windows and the event loop fit together, how to check your install and when to choose it.
- Your First Tkinter Window Create a Tkinter window and control its title, size, position, resizing, icon, transparency and closing behavior, with the geometry string explained in detail.
- The Tkinter Event Loop Explained Understand how Tkinter's mainloop works, why long tasks freeze a window, and how callbacks, after() timers and update_idletasks() keep an interface responsive.
- Structuring Tkinter Programs with Classes Organize Tkinter code with classes: subclass Tk or Frame, keep state in attributes, separate the model from the view, and split big windows into reusable parts.
Widgets Basics
- Tkinter Labels, Fonts and Colors Use Tkinter Label and Message widgets, choose fonts with tuples or the font module, set colors by name or hex, add images and update text while the program runs.
- Tkinter Buttons and Command Callbacks Create Tkinter buttons, pass arguments to callbacks with lambda and functools.partial, avoid the late-binding loop bug, disable buttons and style them with images.
- Tkinter Variables: StringVar, IntVar and trace Learn Tkinter control variables: StringVar, IntVar, DoubleVar and BooleanVar, how textvariable links widgets, how trace reacts to changes, and common pitfalls.
- The Tkinter Entry Widget Use the Tkinter Entry widget for single-line input: read, insert and delete text with indexes, hide passwords, add placeholders and validate input as the user types.
- The Tkinter Text and ScrolledText Widgets Work with the multi-line Tkinter Text widget: line.column indexes, reading and inserting text, tags for styling, search, undo, scrollbars and ScrolledText.
- Tkinter Checkbutton and Radiobutton Offer choices with Tkinter Checkbutton and Radiobutton: onvalue and offvalue, shared variables for radio groups, command callbacks, indicator styles and OptionMenu.
- Tkinter Listbox and Scrollbar Show and pick from lists with the Tkinter Listbox: insert and delete items, selection modes, curselection, virtual events, and connect a Scrollbar properly.
- Tkinter Scale, Spinbox and Progress Widgets Pick numbers with Tkinter's Scale slider and Spinbox, set range, resolution and increment, react to changes, and show progress with the ttk Progressbar.
- Tkinter Frame, LabelFrame and Toplevel Group widgets with Tkinter Frame and LabelFrame, nest containers, scroll big forms with a Canvas, and open extra windows with Toplevel. Includes widget tree tools.
Layout Managers
- The Tkinter pack() Layout Manager Master Tkinter's pack geometry manager: side, fill, expand, anchor, padding and ipadding, packing order, the cavity model and typical toolbar and sidebar layouts.
- The Tkinter grid() Layout Manager Build aligned forms and tables with Tkinter's grid manager: row and column, sticky, spans, padding, weights for resizing, uniform columns and grid helper methods.
- The Tkinter place() Layout Manager Position Tkinter widgets exactly with place(): absolute x and y, relative relx and rely, anchor, relwidth, overlays and badges, plus when not to use place at all.
- Responsive Tkinter Layouts and Resizing Make Tkinter windows resize gracefully: weights, minsize, PanedWindow splitters, reflowing card grids on Configure events, DPI scaling and layout debugging tips.
Events and Bindings
- Tkinter bind() and Event Handling Handle events in Tkinter with bind: event patterns, the event object, bind_all and bind_class, bindtags order, returning break, virtual events and event_generate.
- Tkinter Keyboard and Mouse Events Handle keys, shortcuts, clicks, drags, double-clicks, hover and the mouse wheel in Tkinter, including keysym names, modifier state bits and cross-platform wheel handling.
- Tkinter Timers, Focus and Background Threads Use after() for timers, debounce and animation, manage keyboard focus and tab order, and run slow work in background threads safely with a queue and polling.
Dialogs and Menus
- Message Boxes: showinfo, askyesno and Friends Learn Tkinter message boxes: show information, warnings and errors, ask yes/no or retry questions, read each return value and keep your code testable.
- File Dialogs, Color Chooser and simpledialog Open and save files with Tkinter's filedialog, pick colors with colorchooser, ask for a single value with simpledialog, and handle Cancel correctly.
- Menus, Context Menus and Menubuttons in Tkinter Build a Tkinter menu bar with File and Edit menus, checkbutton and radiobutton items, keyboard shortcuts, right-click context menus and Menubutton widgets.
- Toplevel Windows and Custom Dialogs in Tkinter Open extra windows with Tkinter Toplevel, make them modal with grab_set and wait_window, return values from a custom dialog and close them safely.
Canvas and Drawing
- Tkinter Canvas: Drawing Shapes, Lines and Text Learn the Tkinter Canvas coordinate system and draw lines, rectangles, ovals, arcs, polygons and text, with item options and helper math for stars and circles.
- Canvas Tags, Moving Items, Images and Scrolling Control Tkinter canvas items after drawing: tags, move, coords, itemconfig, delete, stacking order, PhotoImage references and a scrollable canvas.
- Tkinter Animation with after(): Moving Items on a Canvas Animate a Tkinter canvas without freezing the window: use after() instead of sleep, build a frame loop with delta time, bounce a ball and start or stop safely.
- Canvas Mouse Drawing, Dragging Items and Hit Testing Draw freehand lines with the mouse, drag canvas items, find what was clicked with find_closest and find_overlapping, and add undo to a Tkinter drawing.
Styling with ttk
- ttk Themed Widgets: Button, Entry, Combobox, Progressbar Move from classic tk widgets to modern ttk: Label, Button, Entry, Checkbutton, Combobox, Spinbox, Scale and Progressbar, with variables, states and validation.
- ttk Styles and Themes: Custom Colors, Fonts and State Maps Restyle Tkinter ttk widgets with ttk.Style: switch themes, configure custom style names, use map() for hover and disabled states, and set app-wide fonts.
- Tkinter Treeview: Tables, Trees, Sorting and Scrollbars Use ttk.Treeview as a data table or hierarchical tree: define columns, insert, edit and delete rows, read the selection, sort by clicking headings and add scrollbars.
- Notebook, PanedWindow, LabelFrame and Scrollable Frames Organize a Tkinter window with ttk.Notebook tabs, resizable PanedWindow panes, LabelFrame groups, separators and a scrollable frame built from a Canvas.
Packaging and Patterns
- Structuring Tkinter Apps with Classes and Multiple Pages Organize a Tkinter program with classes: subclass Tk and Frame, share state between pages, switch screens, use callbacks and virtual events, and lay out files.
- Separating Logic from the GUI: Models, Views and Testing Split a Tkinter app into model, view and presenter, test the logic with unittest without opening a window, and use fake views and injected dependencies.
- Threads and Background Work in Tkinter (queue and after) Run slow tasks without freezing a Tkinter window: use a worker thread, send results through queue.Queue, poll with after(), support cancel and progress.
- Packaging a Tkinter App: PyInstaller, Resources and Settings Turn a Tkinter program into an .exe or app with PyInstaller: one-file builds, bundled images and icons, resource paths, user settings files and common build errors.
Projects and Practice
- Project: Build a Calculator with Tkinter Build a calculator in Tkinter: a tested calculation engine, a safe expression parser without eval, a grid of buttons, keyboard input, history and error handling.
- Project: A To-Do List App with Saving, Filters and Undo Build a Tkinter to-do app: a tested task model with priorities and due dates, JSON persistence, filters, undo, and a Treeview window wired with a presenter.
- Project: A Paint Program with Tools, Undo/Redo and SVG Export Build a Tkinter paint program: pen, line, rectangle, oval and eraser tools, color and width controls, undo/redo history, and saving the drawing as SVG.
- Tkinter Practice Exercises with Solutions and Project Ideas Practice Tkinter with ten graded exercises: converters, timers, validation, tic-tac-toe, password meter and more, with tested logic solutions and project ideas.