Creating Colorful Popup Progress Bars in Python with Tkinter, tqdm, and rich
This tutorial explains how to build various colorful, popup-style progress bars for desktop applications using Python's Tkinter library together with tqdm or rich, covering installation, basic and styled examples, label integration, multithreading, and custom styling.
Dynamic progress bars are useful for desktop applications and command‑line tools to show task status. This article demonstrates how to create colorful popup progress bars in Python using the Tkinter GUI library, optionally combined with the tqdm or rich libraries for enhanced visual feedback.
Preparation : Ensure the required packages are installed – pip install tqdm for tqdm and pip install rich for rich.
Example 1 – Basic Tkinter Progress Bar
Creates a simple horizontal progress bar that updates from 0% to 100%.
import tkinter as tk
from tkinter import ttk
def run_progress():
for i in range(101):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 2 – Colored Tkinter Progress Bar
Applies three color styles (red, yellow, green) to the progress bar based on the current percentage.
import tkinter as tk
from tkinter import ttk
def run_progress():
for i in range(101):
progress['value'] = i
if i < 33:
progress['style'] = 'red.Horizontal.TProgressbar'
elif i < 66:
progress['style'] = 'yellow.Horizontal.TProgressbar'
else:
progress['style'] = 'green.Horizontal.TProgressbar'
root.update_idletasks()
root.after(50)
root = tk.Tk()
style = ttk.Style()
style.theme_use('default')
style.configure('red.Horizontal.TProgressbar', background='red')
style.configure('yellow.Horizontal.TProgressbar', background='yellow')
style.configure('green.Horizontal.TProgressbar', background='green')
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 3 – Tkinter Progress Bar with tqdm
Shows tqdm's console progress bar while the Tkinter window displays a synchronized progress bar.
import tkinter as tk
from tkinter import ttk
from tqdm import tqdm
def run_progress():
for i in tqdm(range(101)):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 4 – Progress Bar with Text Label
Adds a label below the bar to display the current percentage.
import tkinter as tk
from tkinter import ttk
def run_progress():
for i in range(101):
progress['value'] = i
label.config(text=f'Progress: {i}%')
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
label = ttk.Label(root, text='')
label.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 5 – Tkinter Progress Bar with rich
Uses rich's track function for console progress while updating the Tkinter bar.
import tkinter as tk
from tkinter import ttk
from rich.progress import track
def run_progress():
for i in track(range(101), description="Processing..."):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 6 – Multithreaded Tkinter Progress Bar
Runs the progress update in a separate thread to keep the UI responsive.
import tkinter as tk
from tkinter import ttk
from threading import Thread
def run_progress():
for i in range(101):
progress['value'] = i
root.update_idletasks()
root.after(50)
def start_progress():
thread = Thread(target=run_progress)
thread.start()
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=start_progress)
button.pack(pady=20)
root.mainloop()Example 7 – Custom Styled Progress Bar
Defines a custom style with a black trough and blue background.
import tkinter as tk
from tkinter import ttk
def run_progress():
for i in range(101):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
style = ttk.Style()
style.theme_use('default')
style.configure('Custom.Horizontal.TProgressbar', troughcolor='black', background='blue')
progress = ttk.Progressbar(root, style='Custom.Horizontal.TProgressbar', orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 8 – Tkinter with tqdm Animation
Combines tqdm's console animation with the Tkinter progress bar.
import tkinter as tk
from tkinter import ttk
from tqdm import tqdm
def run_progress():
for i in tqdm(range(101)):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 9 – Tkinter with rich Animation
Shows rich's console progress alongside the Tkinter bar.
import tkinter as tk
from tkinter import ttk
from rich.progress import track
def run_progress():
for i in track(range(101), description="Processing..."):
progress['value'] = i
root.update_idletasks()
root.after(50)
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=run_progress)
button.pack(pady=20)
root.mainloop()Example 10 – Multithreaded Tkinter with rich
Runs rich's progress in a separate thread to keep the GUI responsive.
import tkinter as tk
from tkinter import ttk
from threading import Thread
from rich.progress import track
def run_progress():
for i in track(range(101), description="Processing..."):
progress['value'] = i
root.update_idletasks()
root.after(50)
def start_progress():
thread = Thread(target=run_progress)
thread.start()
root = tk.Tk()
progress = ttk.Progressbar(root, orient='horizontal', length=200, mode='determinate')
progress.pack(pady=20)
button = ttk.Button(root, text='Start', command=start_progress)
button.pack(pady=20)
root.mainloop()These examples illustrate how to use Tkinter together with tqdm or rich to create a variety of colorful, popup‑style progress bars, which can be adapted and extended to fit specific application requirements.
Test Development Learning Exchange
Test Development Learning Exchange
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.