Creating A Progress Bar (Python)

An item I have felt missing from my Python projects when using the Tkinter modules is a progress bar. I’ve decided to correct that.

——

#!/bin/python3
# geektechstuff
# progress bar
# modules to import
from tkinter import *
# ttk makes the window look like running Operating System’s theme
from tkinter import ttk
# create root tkinter window to hold progress bar
root = Tk()
# create progress bar
progress = ttk.Progressbar(root, orient = HORIZONTAL, length = 120)
# pack progress bar into root
progress.pack()
# to step progress bar up
progress.config(mode = ‘determinate’,maximum=100, value = 5)
progress.step(5)
# to have an moving bar that doesn’t indicate how long it will take
progress.config(mode=’indeterminate’)
# to start indeterminate bar
progress.start()
# to stop indeterminate bar
progress.stop()
——-
python_tkinter_progressbar_1
Python Progress Bar

Tkinter allows for either a determinate or indeterminate progress bar to be created.

python_tkinter_progressbar_3
Python Determinate Progress Bar

A “determinate” progress bar allows for the bar to increase in steps, which is great if there is code to go in between each stepped increase. This would give the person running the code a visual estimate of how long the processes will take.

python_tkinter_progressbar_2
Python Indeterminate Progress Bar

An “indeterminate” progress bar is used to show that the program is running but does not give any indication of how long the process will take.

 

The ttk from tkinter makes tkinter windows take on the look/theme of the operating system running the Python program. So on my Mac the tk window takes on the theme of MacOS Mojave, but on my Windows 10 device it takes on a Windows 10 1809 theme.

 

3 responses to “Creating A Progress Bar (Python)”

  1. OnClick360 Avatar
    OnClick360

    Very well explained article it really helps me a lot.
    Jenkins installation on windows

    Like

  2. Тони Цеков Avatar
    Тони Цеков

    ,i have one question,is it possible the indikator to start from the middle and when be move after that about 2 minutes to return alone in the middle,it is will be difficult to asure..Thank you boys for your help.

    Like

  3. Chris Norman Avatar
    Chris Norman

    What about using this progress bar as a part of a repeat loop?

    Like

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect