🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreeTkinter GUI Widgets

Tkinter is Python’s standard GUI library. It ships with every Python installation, requires no separate installation, and provides enough widgets to build real desktop applications. This guide walks through the most commonly used Tkinter widgets, with working examples you can run right away.
Each widget handles a specific UI role – from displaying text to accepting user input. Once you know what each one does, combining them with layout managers like pack() and grid() lets you build complete interfaces.
TLDR
- Label – displays read-only text or images
- Button – triggers a function when clicked
- Checkbutton – toggle for on/off states with IntVar
- Entry – single-line text input with StringVar
- Scale – slider for numeric values within a range
- Listbox – scrollable list for single or multiple selection
- Radiobutton – mutually exclusive single-choice buttons
Setting Up the Main Window
Every Tkinter application follows the same three-step pattern: import the library, create the root window, and start the event loop.
import tkinter as tk
# Create the root window
root = tk.Tk()
root.title("My First GUI App")
root.geometry("400x300") # Width x Height in pixels
# Your widgets go here
label = tk.Label(root, text="Hello, Tkinter!")
label.pack()
# Start the event loop
root.mainloop()
tk.Tk() creates the main application window. geometry() sets its dimensions in pixels. mainloop() runs the event listener for clicks, keystrokes, and other user interactions – the program stays here until the window is closed. Everything between creating the window and calling mainloop() is where you assemble your interface.
Label – Display Text and Images
The Label widget displays read-only text or images. It is the simplest widget and appears throughout Tkinter applications for headings, descriptions, status messages, and image previews.
import tkinter as tk
root = tk.Tk()
root.title("Label Demo")
root.geometry("400x200")
# Basic text label
title_label = tk.Label(
root,
text="Welcome to Tkinter!",
font=("Arial", 18, "bold"),
fg="darkblue"
)
title_label.pack(pady=10)
# Label with wrapping and center alignment
description = tk.Label(
root,
text="Labels display static text. They are read-only - "
"use Entry widgets for user input.",
font=("Arial", 10),
fg="gray",
wraplength=350,
justify="center"
)
description.pack(pady=10)
# Label with background color
highlight = tk.Label(
root,
text="Colored backgrounds are easy too!",
font=("Arial", 12, "italic"),
bg="lightyellow",
padx=20,
pady=10
)
highlight.pack(pady=10)
root.mainloop()
Common Label parameters: text sets the displayed string, font controls typography, fg sets text color, bg sets background color, wraplength controls line width, and justify sets text alignment.
Button – Trigger Actions on Click
Buttons are interactive widgets that call a function when clicked. You pass the function reference to the command parameter – pass the function name without parentheses.
import tkinter as tk
def on_click():
label.config(text="Button was clicked!", fg="green")
def on_reset():
label.config(text="Press the button above", fg="black")
root = tk.Tk()
root.title("Button Demo")
root.geometry("400x200")
label = tk.Label(root, text="Press the button below", font=("Arial", 14))
label.pack(pady=30)
# A regular button
my_button = tk.Button(
root,
text="Click Me!",
command=on_click,
font=("Arial", 12),
bg="cornflowerblue",
fg="white",
padx=20,
pady=5,
cursor="hand2"
)
my_button.pack(pady=10)
# A reset button
reset_button = tk.Button(
root,
text="Reset",
command=on_reset,
font=("Arial", 10),
bg="lightgray"
)
reset_button.pack(pady=5)
root.mainloop()
When a button is clicked, Tkinter calls the function assigned to command. Both buttons above modify the same Label by calling different functions – demonstrating how multiple widgets interact through shared functions. The cursor="hand2" parameter gives the button a hand cursor on hover.
Checkbutton – Toggle Boolean States
A Checkbutton is a two-state toggle – checked or unchecked. It pairs with an IntVar to store its state. When the user checks or unchecks it, the variable automatically updates to 1 or 0.
import tkinter as tk
def show_settings():
output = []
if python_check.get():
output.append("Python enabled")
if java_check.get():
output.append("Java enabled")
if cpp_check.get():
output.append("C++ enabled")
if not output:
output.append("No languages selected")
result_label.config(text="\n".join(output))
root = tk.Tk()
root.title("Checkbutton Demo")
root.geometry("400x250")
intro = tk.Label(root, text="Select your programming languages:",
font=("Arial", 12, "bold"))
intro.pack(pady=10)
# IntVar stores 1 (checked) or 0 (unchecked)
python_check = tk.IntVar()
java_check = tk.IntVar()
cpp_check = tk.IntVar()
tk.Checkbutton(
root,
text="Python",
variable=python_check,
command=show_settings,
font=("Arial", 11)
).pack(anchor="w", padx=100)
tk.Checkbutton(
root,
text="Java",
variable=java_check,
command=show_settings,
font=("Arial", 11)
).pack(anchor="w", padx=100)
tk.Checkbutton(
root,
text="C++",
variable=cpp_check,
command=show_settings,
font=("Arial", 11)
).pack(anchor="w", padx=100)
result_label = tk.Label(root, text="No languages selected",
font=("Arial", 10), fg="green")
result_label.pack(pady=20)
root.mainloop()
Each Checkbutton gets its own IntVar. When you click a checkbox, Tkinter automatically sets that variable to 1 or 0. Set the initial state with python_check.set(1). This widget suits settings panels, feature toggles, and multi-select scenarios.
Entry – Single-Line Text Input
The Entry widget accepts a single line of text input. It works with a StringVar to read and write its value. Use .get() to retrieve the current text and .set() to change it programmatically.
<pre class="wp-block-syntaxhighlighter-code">
import tkinter as tk
def submit():
name = name_var.get()
if name.strip():
greeting.config(text=f"Hello, {name.strip()}! Welcome to Tkinter.")
else:
greeting.config(text="Please enter your name.")
def clear():
name_var.set("")
greeting.config(text="")
root = tk.Tk()
root.title("Entry Demo")
root.geometry("400x220")
tk.Label(root, text="Enter your name:",
font=("Arial", 12, "bold")).pack(pady=10)
# StringVar to hold the entry text
name_var = tk.StringVar()
entry = tk.Entry(root, textvariable=name_var, font=("Arial", 12), width=30)
entry.pack(pady=5)
# Focus the cursor here automatically when the window opens
entry.focus()
# Bind the Enter key to submit
entry.bind("<Return>", lambda e: submit())
submit_btn = tk.Button(root, text="Submit", command=submit,
font=("Arial", 11), bg="steelblue", fg="white")
submit_btn.pack(pady=5)
clear_btn = tk.Button(root, text="Clear", command=clear,
font=("Arial", 11), bg="lightgray")
clear_btn.pack(pady=5)
greeting = tk.Label(root, text="", font=("Arial", 13, "italic"), fg="navy")
greeting.pack(pady=15)
root.mainloop()
</pre>
entry.bind(" binds the Enter key to the submit function, so pressing Enter triggers the same action as clicking the button. The focus() call ensures the text field is ready when the window opens.
Scale – Slider for Numerical Input
The Scale widget provides a draggable slider for selecting a numeric value within a range. It suits volume controls, color pickers, and any scenario where picking a value within a range is more intuitive than typing a number.
import tkinter as tk
def show_value(value):
result.config(text=f"Selected value: {value}")
root = tk.Tk()
root.title("Scale Demo")
root.geometry("400x300")
tk.Label(root, text="Adjust the volume:",
font=("Arial", 14, "bold")).pack(pady=10)
# IntVar to track the scale value
volume = tk.IntVar()
volume.set(50) # Default value
# A horizontal scale from 0 to 100
scale = tk.Scale(
root,
from_=0, # Minimum value
to=100, # Maximum value
orient="horizontal",
variable=volume,
command=show_value,
length=300,
tickinterval=20,
showvalue=True
)
scale.pack(pady=20)
result = tk.Label(root, text="Selected value: 50",
font=("Arial", 12), fg="darkgreen")
result.pack(pady=10)
# Button to print the current value
tk.Button(root, text="Confirm Volume",
command=lambda: print(f"Volume set to: {volume.get()}"),
font=("Arial", 11), bg="darkgreen", fg="white").pack(pady=5)
root.mainloop()
Key Scale parameters: from_ and to define the range, orient controls horizontal or vertical layout, tickinterval adds tick marks at intervals, and showvalue displays the current numeric value above the slider. The command callback receives the current value as a string argument each time the slider moves.
Listbox – List Selection
The Listbox widget displays a scrollable list of items. It supports single or multiple selection, and you retrieve selected item(s) with curselection().
<pre class="wp-block-syntaxhighlighter-code">
import tkinter as tk
def show_selection():
selection = languages_listbox.curselection()
if selection:
selected = languages_listbox.get(selection[0])
result.config(text=f"You selected: {selected}")
else:
result.config(text="No item selected")
root = tk.Tk()
root.title("Listbox Demo")
root.geometry("400x300")
tk.Label(root, text="Choose a programming language:",
font=("Arial", 13, "bold")).pack(pady=10)
# Create and populate the listbox
languages_listbox = tk.Listbox(root, font=("Arial", 12), height=8)
languages = ["Python", "Java", "C++", "JavaScript", "Rust",
"Go", "TypeScript", "Kotlin"]
for lang in languages:
languages_listbox.insert("end", lang)
languages_listbox.pack(pady=5)
# Select the first item by default
languages_listbox.select_set(0)
# Bind double-click to selection
languages_listbox.bind("<Double-Button-1>", lambda e: show_selection())
tk.Button(root, text="Confirm Selection",
command=show_selection,
font=("Arial", 11), bg="purple", fg="white").pack(pady=5)
result = tk.Label(root, text="", font=("Arial", 11), fg="purple")
result.pack(pady=10)
root.mainloop()
</pre>
curselection() returns a tuple of selected indices. Use listbox.get(index) to retrieve the item at a given index. insert("end", item) adds items to the end of the list. For multiple selection mode, set selectmode="multiple" and iterate over curselection() to handle multiple indices.
Radiobutton – Mutually Exclusive Choices
Radiobutton widgets belong to a group where only one can be selected at a time. They share an IntVar, and each button is associated with a different value. Selecting a new button automatically deselects the previous one.
import tkinter as tk
def show_choice():
result.config(text=f"You chose: {choice.get()} (value: {choice.get()})")
root = tk.Tk()
root.title("Radiobutton Demo")
root.geometry("400x280")
tk.Label(root, text="Select your experience level:",
font=("Arial", 13, "bold")).pack(pady=10)
# Single IntVar shared across all radio buttons
choice = tk.IntVar()
choice.set(1) # Default selection
# Radiobutton with integer value
tk.Radiobutton(
root,
text="Beginner - I'm just starting out",
variable=choice,
value=1,
command=show_choice,
font=("Arial", 11)
).pack(anchor="w", padx=80, pady=3)
tk.Radiobutton(
root,
text="Intermediate - I know the basics",
variable=choice,
value=2,
command=show_choice,
font=("Arial", 11)
).pack(anchor="w", padx=80, pady=3)
tk.Radiobutton(
root,
text="Advanced - I build complex applications",
variable=choice,
value=3,
command=show_choice,
font=("Arial", 11)
).pack(anchor="w", padx=80, pady=3)
tk.Radiobutton(
root,
text="Expert - I contribute to open source",
variable=choice,
value=4,
command=show_choice,
font=("Arial", 11)
).pack(anchor="w", padx=80, pady=3)
result = tk.Label(root, text="You chose: 1 (value: 1)",
font=("Arial", 12, "italic"), fg="darkred")
result.pack(pady=20)
root.mainloop()
All four Radiobutton widgets share the same choice variable. When one is selected, choice.get() returns that button’s assigned value. This mutual exclusivity makes radio buttons the right choice for single-option selections like experience level, payment method, or subscription tier.
FAQ
Q: How do I run a Tkinter application?
Save your Python code to a file with a .py extension and run it with python filename.py. The application launches in a native window. Tkinter applications require an active display environment to render GUI windows.
Q: What is the difference between pack() and grid()?
pack() places widgets in a single direction – either top-to-bottom (default) or left-to-right. grid() places widgets in a table of rows and columns, giving fine control over precise layout. place() positions widgets at absolute pixel coordinates. Mix these layout managers within the same application as needed.
Q: Can Tkinter display images?
Yes. Use the PhotoImage class for GIF and PNG formats. For other image formats, use the PIL library with ImageTk.PhotoImage. Assign the image to a Label widget with label.config(image=photo).
Q: How do I handle multiple windows?
Create additional tk.Toplevel() windows. These are secondary windows that depend on the main window. When the main window closes, all Toplevel windows close as well.
Tkinter provides a complete GUI toolkit out of the box. These seven widgets cover the foundations of most Tkinter applications. Combine them with layout managers to arrange them on screen, and you will be building functional desktop interfaces in short order.


