The chapter in short
A graphical user interface (GUI) lets users interact with a program through windows, buttons and other widgets rather than typed commands.
The chapter covers GUI design principles and building simple GUIs in Python with Tkinter: windows, labels, buttons, entry boxes, layout managers and event handling.
GUIWidgetEventEvent handlerLayout manager
Key points
- A GUI is built from widgets such as labels, buttons and text boxes.
- Tkinter is Python's standard GUI library.
- Layout managers (pack, grid, place) arrange widgets.
- Event-driven programming responds to user actions such as clicks.
- A callback function runs when an event happens.
- Good GUIs are simple, consistent and give clear feedback.
Definitions
- 1
GUI
A graphical user interface using windows, icons and buttons.
- 2
Widget
A GUI element such as a button or label.
- 3
Event
An action such as a click or key press.
- 4
Event handler
A function that runs in response to an event.
- 5
Layout manager
A tool that positions widgets in a window.
Formulas
Tkinter window
import tkinter as tk root = tk.Tk() tk.Button(root, text="OK").pack() root.mainloop()