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


