Tutorial #78: Creating Progress Bars in Tkinter Using Python

Posted by


In this tutorial, we will be creating progress bars using the Tkinter library in Python. Progress bars are a great way to visually represent the progress of a task and can add a professional touch to your GUI applications.

To get started, make sure you have Tkinter installed on your system. Tkinter comes pre-installed with Python, so no additional installation should be needed. If you don’t have Tkinter installed, you can install it using the command pip install tk.

Let’s start by importing the necessary modules:

from tkinter import *
from tkinter.ttk import *

Next, let’s create a basic Tkinter window with a progress bar:

root = Tk()
root.title("Progress Bar Tutorial")

progress = Progressbar(root, orient = HORIZONTAL, length = 300, mode = 'determinate')
progress.pack(pady = 10)

In the code above, we create a Tkinter window and a progress bar widget. The orient parameter specifies the orientation of the progress bar (horizontal in this case), the length parameter specifies the length of the progress bar, and the mode parameter specifies how the progress bar should behave (determinate in this case, meaning it will show a specific amount of progress).

Next, let’s create a function that will update the progress bar:

def update_progress():
    progress['value'] += 10
    if progress['value'] < 100:
        root.after(500, update_progress)

In the update_progress function, we increase the value of the progress bar by 10 (you can adjust this value based on your requirements) and schedule the function to be called again after 500 milliseconds. This creates an animation effect where the progress bar gradually fills up until it reaches 100%.

Finally, let’s bind the update_progress function to a button so that the progress bar starts updating when the button is clicked:

btn = Button(root, text = "Start Progress", command = update_progress)
btn.pack(pady = 10)

Now, when you run the code and click the "Start Progress" button, you should see the progress bar filling up gradually until it reaches 100%.

You can customize the progress bar further by changing its colors, font, and other properties. Check the Tkinter documentation for more options and functionalities.

That’s it for this tutorial! You have now successfully created a progress bar with Tkinter in Python. Experiment with different settings and functionalities to create the perfect progress bar for your GUI applications.

0 0 votes
Article Rating

Leave a Reply

44 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Codemycom
2 hours ago

▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My YouTube Channel:
http://bit.ly/2UFLKgj http://bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
https://Codemy.com http://bit.ly/2GFmOBz
▶️ Learn to Code at https://Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 http://bit.ly/2VC9WUN

@kapibara2440
2 hours ago

Thank you 😊

@Not_A_Lazy_Dev
2 hours ago

thx bro i needed the root.update_idletasks() thingy

@GameplayAce
2 hours ago

How do i set a max value to my progress bar? let's say i want it to be full at when the value equals to 1500? and how to i sum values into it as a number, let's say i wanna add 15 to the bar i just mentioned instead of adding up % of the full value as you did in the video, how can i do that?

@mosoliman7992
2 hours ago

watching this video solved my issue of my function not displaying whats happening as its doing it

@safwankhan199
2 hours ago

Hey John, very neat feature!

I was just thinking about how a progress bar's value could be updated dynamically in reference to some function (bound to a button).

So for example, once the button is pressed, the progress bar is initialized to 0, but as the function is being run, the progress bar is moving along with it.

Once the function is done executing, hence the progress bar reaches 100% and spits out the function's result.

How would that type of functionality be implemented?

Thanks, Safwan

@aaroncatolico7550
2 hours ago

Dammit! I broke the LIKE 👍🏻 button! I "SMASHED!" the like button too hard because of you, John!

@MikeSmith-eo6ft
2 hours ago

rom tkinter import *
from tkinter.ttk import *
from tkinter import ttk
import time

root = Tk()
root.title('Demo')
root.geometry("600×400")

my_progress = ttk.Progressbar(root, orient=HORIZONTAL,
length = 300, mode="determinate")

def step():
my_progress['value'] = 0
for x in range(100):
my_progress['value'] += 1
root.update_idletasks()
my_label.config(text=my_progress['value'])
time.sleep(.05)
def stop():
my_progress.stop()
my_progress.pack(pady=20)
my_button = Button(root,text='Progess', command=step)
my_button.pack(pady=10)
my_button2 = Button(root, text='stop', command=stop)
my_button2.pack(pady=5)
my_label = Label(root, text="")
my_label.pack(pady=10)
root.mainloop()

this is how to update through the for loop, you placed your label update before the increment making your label 1 step behind

@nikolacesarovic
2 hours ago

Thank you sir

@jonathan19910728
2 hours ago

I have a question. Generally, the external software will jump out of a new window and then run, and it will automatically shut down after running. What should I do?

@TipsTricksSolutions
2 hours ago

Is there a way to connect this progress bar with the pytube progress bar?

@eesakamaldien1917
2 hours ago

your videos are the best

@bricklee4744
2 hours ago

Found a thing makes me confused: When I define the progressbar using a new line for ".pack()", it works, once I use the cascade formation link "ttk.Progressbar().pack()", there will be an error, and the error is about the 'value' in the setp founction.

@RyanDanielG
2 hours ago

Hit that like button Python Fans! Great tutorial. Feed the Algorithm!

@dragoneater2008_
2 hours ago

How do I make a python tkinter downloader with a progress bar?

@kanwaradnan4849
2 hours ago

When i press start button I'm unable to use any other widget of app. How can i solve this??

@aydenshahraki1084
2 hours ago

How can I use if statements with the progress bars?

@devenjain7116
2 hours ago

Is it possible to bind a progress bar to a function and that way, when the function completes its execution, the progress bar will complete and actually make sense and be of use instead of just a decoration! 🙂

@grmmth3
2 hours ago

100

@alwynjoby9604
2 hours ago

Hello Sir!
I tried this but unfortunately it returns me an error like "module 'tkinter.ttk' has no attribute 'ProgressBar'"! I dont know what to do! Could you please help me out!

44
0
Would love your thoughts, please comment.x
()
x