liveBook · Manning

Tkinter

As explained in Get Programming: Learn to code with Python

tkinter is Python's standard-library interface to the Tcl/Tk toolkit for building graphical user interfaces.

tkinter is Python’s standard-library interface for building graphical user interfaces with Tcl/Tk. It connects programs to windows, widgets, and user actions such as button clicks or menu selections. section 37.1

A basic tkinter application grows through three practical steps:

  • Create and customize a window by setting its size, location, title, or background color. section 37.1 section 37.2
  • Create widgets such as buttons, text fields, labels, menus, checkboxes, or sliders, then place them in the window. section 37.3
  • Choose widget behaviors by writing event-handler functions for user interactions. section 37.1
Listing 37.1. Creating a window
import tkinter                               #1

window = tkinter.Tk()                        #2
window.geometry("800x200")                   #3
window.title("My first GUI")                 #4
window.configure(background="grey")          #5
window.mainloop()                            #6

The small window example shows the essential sequence: import tkinter, create a Tk window, configure it, and start its main loop. section 37.2

Widgets make the interface useful. A button, entry field, and label can form a small color-changing interface, while a canvas can draw shapes. Larger projects can use classes, keyboard input, and a canvas, such as a two-player game of tag. section 37.3 section 38.0

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains window setup and widget placement with listings, but stops short of detailed event-handler implementation.
Examples
Uses configured windows, colored buttons, an entry field, a label, and a two-player tag game.
What you can do after
Builds simple GUI programs and interactive games with windows, widgets, keyboard controls, and canvases.
How it connects
Connects windows with widgets, event handlers, keyboard input, canvases, classes, and object-oriented programming.

Also explained in

Compare how 3 books explain tkinter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.