Python Tkinter - Introduction

What is Tkinter?
Tkinter is the standard GUI (Graphical User Interface) library for Python.provides tools to create windows, buttons, textboxes, labels, and other graphical elements that help users interact with your application visually. It is built on top of the Tcl/Tk GUI toolkit, and it comes bundled with Python, so you don't need to install it separately.
Basic App Structure
Example.py
import tkinter as tk # Create the main window root = tk.Tk() root.title("Simple Tkinter App") root.geometry("300x200") # Create a label label = tk.Label(root, text="Hello, World!") label.pack(pady=20) # Run the application root.mainloop()
Output
This is the output of the code above, showing the basic window layout and displaying the text 'Hello World'.

Significance of Tkinter
- Built-in GUI library in Python (no need for installation).
- Cross-platform: Works on Windows, macOS, and Linux.
- Simple and beginner-friendly: Great for learning GUI programming.
- Wide range of widgets: Buttons, labels, entry boxes, menus, and more.
- Customizable: You can change fonts, colors, and layout easily.
- Event-driven: Responds to user inputs like mouse clicks or key presses.
Why Do We Use Tkinter?
- Build desktop GUI applications using Python.
- Create user-friendly interfaces for scripts and tools.
- Build apps like:
- Calculator
- Form submission apps
- Notepad
- Games with buttons and labels
- Inventory or student management systems
Tkinter is perfect for small to medium desktop apps that don't require advanced GUI features or modern design aesthetics.
Widgets | Definition / Purpose |
---|---|
Label | Displays text or images. |
Button | Creates a clickable button. |
Entry | Single-line text input field. |
Text | Multi-line text input area. |
Frame | Container to group widgets. |
Checkbutton | Checkbox for on/off (True/False) options. |
Radiobutton | Set of buttons where only one can be selected. |
Listbox | Displays a list of items for selection. |
Canvas | Widget for drawing shapes, images, or custom graphics. |
Scrollbar | Adds scrolling ability to widgets like Text, Listbox, or Canvas. |
Scale | Slider for selecting a numerical value. |
Spinbox | Input box with up/down arrows to increment/decrement values. |
Menu | Menu bar for creating dropdown menus. |
Menubutton | Button that displays a menu when clicked. |
PanedWindow | Container with adjustable panes. |
LabelFrame | Frame with a label on top. Used for grouping widgets. |
Toplevel | Creates a new top-level window separate from the root. |
Message | Similar to Label, but supports automatic text wrapping. |
Combobox | Dropdown menu (from ttk module). |
Treeview | Table/tree structure for displaying hierarchical data (from ttk). |
Notebook | Tabbed layout (from ttk). |
Progressbar | Displays a horizontal or vertical progress indicator (from ttk). |
Separator | Draws a horizontal or vertical line to separate widgets (from ttk). |
Dialog | Predefined dialog boxes like message boxes, file dialogs, etc. |
Messagebox | Displays informational, warning, error, or question dialogs (tk.messagebox). |
OptionMenu | Drop-down menu for selecting from a list of options. |