Creating Customizable Progress Bars in Python

If you have never added a progress bar to your Python script, you might assume it introduces unnecessary complexity or is hard to maintain. In reality, implementing one requires only a few lines of code. This article demonstrates how to integrate progress bars into command-line scripts and PySimpleGUI-based user interfaces, covering four popular libraries.

1. Progress

The Progress libray offers a straightforward approach. You define the number of iterations, choose a bar style, and update the bar on each step.

import time
from progress.bar import IncrementalBar

items = [1, 2, 3, 4, 5, 6, 7, 8]
bar = IncrementalBar('Processing', max=len(items))
for item in items:
    bar.next()
    time.sleep(1)
bar.finish()

This yields a simple incremental bar. The library provides multiple bar formats (e.g., ChargingBar, FillingSquaresBar) that you can choose from.

Documentation: https://pypi.org/project/progress/1.5/

2. tqdm

The tqdm library is widely used for its minimal syntax and rich features. It automaticaly wraps an iterable and updates the progress bar.

import time
from tqdm import tqdm

items = [1, 2, 3, 4, 5, 6, 7, 8]
for item in tqdm(items):
    time.sleep(1)

The output shows a sleek, colorful bar with estimated time remaining. tqdm also supports manual updates and nested loops.

Documentation: https://tqdm.github.io/

3. Alive Progress

As the name suggests, Alive Progress adds animated spinners and dynamic effects to make progress bars more engaging.

import time
from alive_progress import alive_bar

items = [1, 2, 3, 4, 5, 6, 7, 8]
with alive_bar(len(items)) as bar:
    for item in items:
        bar()
        time.sleep(1)

The bar animates with a spinning cursor and flowing progress, offering customizable styles. This library is particularly useful for long-running tasks where visual feedback is essential.

Repository: https://github.com/rsalmei/alive-progress

4. PySimpleGUI

Quick GUI Progress Meter

PySimpleGUI allows you to add a graphical progress meter with a single function call:

import PySimpleGUI as sg
import time

items = [1, 2, 3, 4, 5, 6, 7, 8]
for i, item in enumerate(items):
    sg.one_line_progress_meter('Progress', i+1, len(items), '-meter-')
    time.sleep(1)

This displays a popup window with a progress bar that updates automatically.

Embedded Progress Bar in a PySimpleGUI Application

For a more integrated UI, you can place a progress bar inside a custom window layout:

import PySimpleGUI as sg
import time

items = [1, 2, 3, 4, 5, 6, 7, 8]

progress_layout = [
    [sg.ProgressBar(len(items), orientation='h', size=(51, 10), key='-PROG-')]
]
output_layout = [
    [sg.Output(size=(78, 20))]
]
layout = [
    [sg.Frame('Progress', layout=progress_layout)],
    [sg.Frame('Output', layout=output_layout)],
    [sg.Submit('Start'), sg.Cancel()]
]

window = sg.Window('Custom Progress Meter', layout)
progress_bar = window['-PROG-']

while True:
    event, values = window.read(timeout=10)
    if event in (sg.WIN_CLOSED, 'Cancel'):
        break
    if event == 'Start':
        for i, item in enumerate(items):
            print(item)
            time.sleep(1)
            progress_bar.update_bar(i + 1)

window.close()

This example creates a window with a progress bar frame and an output frame. Clicking "Start" iterates through the list, displaying each item in the output area and advancing the bar.

Integrating a progress bar into your Python script is remarkably simple and eliminates the guesswork of monitoring long-running processes. Whether you prefer command-line tools or graphical interfaces, these libraries offer flexible solutions.

Tags: python progress bar tqdm Progress library Alive Progress

Posted on Mon, 01 Jun 2026 16:13:07 +0000 by Eric T