Creating A Progress Bar (Python)

Python Progress Bar

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 thoughts on “Creating A Progress Bar (Python)

  1. ,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

Comments are closed.