GUI Programming
Tkinter is Python's built-in GUI library that is easiest to learn. With Tkinter, you can create windows, buttons, inputs, labels, and other widgets.
Tkinter comes right with the Python installation — no extra install needed. This makes it the ideal choice for building simple desktop applications such as input forms, admin tools, monitoring dashboards, or quick prototypes. Although its look feels classic, Tkinter is very functional and stable.
The basic structure of a Tkinter application is always the same: create the main window (Tk()), add widgets (Label, Entry, Button, etc.) with a layout manager (pack, grid, place), then run the event loop (mainloop()). This event loop keeps running, waiting for user interactions such as button clicks, text input, or closing the window — every action triggers a registered callback function.
For more modern, visually rich applications, consider PyQt/PySide (Qt), Kivy (mobile), or wxPython (native look). But for learning GUI programming fundamentals and internal applications that don't need a fancy look, Tkinter is still the winner because it is lightweight, quick to learn, and has zero dependencies.
Code Example
import tkinter as tk
from tkinter import messagebox
def on_click():
name = entry.get()
if name:
messagebox.showinfo("Hello", f"Hello, {name}!")
else:
messagebox.showwarning("Warning", "Enter a name!")
# Creating the main window
window = tk.Tk()
window.title("My First App")
window.geometry("300x200")
tk.Label(window, text="Name:").pack(pady=5)
entry = tk.Entry(window)
entry.pack(pady=5)
tk.Button(window, text="Click Me",
command=on_click).pack(pady=10)
window.mainloop()
Code Explanation
The first line imports Tkinter and messagebox. The on_click() function is the callback — called when the button is clicked. Inside it, entry.get() gets the text from the input, then checks whether it is empty. If there is content, messagebox.showinfo() displays a greeting dialog. If it is empty, messagebox.showwarning() appears as a warning.
tk.Tk() creates the main window. The title() and geometry() methods set the window title and size (300x200 pixels). The Label, Entry, and Button widgets are created and placed with .pack() — the simplest layout manager, which stacks widgets vertically. The pady argument gives vertical spacing between widgets.
command=on_click connects the button to the function without parentheses — Python passes a function reference, not a call result. Finally, window.mainloop() starts the event loop; the window stays open and responsive until the user closes it.
Everyday Example
An HR administrator needs a simple application to input new employee data. The form contains fields for name, position, department, and a "Save" button. When the button is clicked, the data is validated (must not be empty), then saved to a CSV file or database. This application can be built in 1-2 hours with Tkinter — much faster than building a web page with a backend server.
Another example: a log viewer application that reads a log file, displays its contents in a Text widget, and has a filter button by level (ERROR, WARN, INFO). Great for ops teams that need a helper tool without having to set up a web server.
Summary
Tkinter is the best gateway into Python GUI programming. Easy to learn, no extra installation, and powerful enough for internal desktop applications and prototypes. Master the three layout managers (pack, grid, place), event handling via command and bind, and basic widgets — that is the foundation for quickly building functional desktop applications.