In this article we want to learn about How to Create Progress Bar in Python Tkinter, creating progress bar is useful feature for displaying progress of an operation in graphical user interface. Tkinter provides an easy widget called Progressbar for creating progress bars. in this article we are going to learn how to create a progress bar in Python Tkinter.
First step is to import the tkinter module:
1 |
import tkinter as tk |
After that we need to create new instance of the Tk class to create new window:
1 |
root = tk.Tk() |
Now we can create new instance of the Progressbar widget:
1 |
progress_bar = Progressbar(root, orient=tk.HORIZONTAL, length=300, mode='determinate') |
In the above code we have created horizontal progress bar with length of 300 pixels and determinate mode, which means that the progress bar shows current progress of an operation as a percentage.
Now we need to pack the progress bar widget into the Tkinter window:
1 |
progress_bar.pack(pady=20) |
In the above code we have used pack method to add the progress bar widget to window and set vertical padding of 20 pixels.
And finally we need to update the value of progress bar widget based on the progress of the operation:
1 |
progress_bar['value'] = 50 |
This is the complete code for this article
1 2 3 4 5 6 7 8 9 10 11 12 |
import tkinter as tk from tkinter.ttk import Progressbar root = tk.Tk() root.geometry("400x200") progress_bar = Progressbar(root, orient=tk.HORIZONTAL, length=300, mode='determinate') progress_bar.pack(pady=20) progress_bar['value'] = 50 root.mainloop() |
In this example we have created new Tkinter window with size of 400×200 pixels. after that we have created new progress bar widget with length of 300 pixels and determinate mode. we packed the progress bar widget into the window and set its value to 50.
Run the complete code and this will be the result
PySide6 GUI Articles
- How to Create Label in PySide6
- How to Create Button in Python & PySide6
- How to Use Qt Designer with PySide6
- How to Add Icon to PySide6 Window
- How to Load UI in Python PySide6
Tkinter provides easy and simple widget for creating progress bars in Python GUI applications. by following the steps that we already have mentioned we can create and customize progress bars.