Tkinter Progressbar Tutorial
Progressbar can be interpreted as a progress bar, and it is mainly used as a pointer to the progress of the work. The user can confirm that the system is still in progress by the progress pointer, and can also see what stage it is at.
The syntax of the Progressbar constructor is as follows.
Progressbar(master, options, ...)
The first parameter of the Progressbar( ) method is the parent object, indicating which parent object this Progressbar will be built in. The following are the other commonly used options parameters within the Progressbar( ) method.
(1) length
: the length of the progress bar, the default is 100 pixels.
(2) mode
: can have the following two modes.
- determinate: a pointer will move from the start to the end, usually this mode can be used when we know the required working time, this is the default mode.
- indeterminate: a pointer will move back and forth between the start and the end point, usually when we don’t know the time needed to work, we can use this mode.
(3) maximum: the maximum value of the progress bar, the default is 100.
(4) name: the name of the progress bar, for the program reference reference.
(5) orient: the direction of the progress bar, can be HORIZONTAL (default) or VERTICAL.
(6) value: the current value of the progress bar.
(7) variable: record the current progress value of the progress bar.
Example#1
The maximum value of the progress bar is 100, and the interface listing the current value is 50. One of the progress bars uses default values for most parameters, the other uses a custom approach.
from tkinter import *
from tkinter.ttk import *
root = Tk()
root.geometry("300x140")
root.title("apidemos.com")
# Create a progress bar using the default settings
pb1 = Progressbar(root)
pb1.pack(pady=20)
pb1["maximum"] = 100
pb1["value"] = 50
# Create a progress bar using each parameter customization method
pb2 = Progressbar(root,orient=HORIZONTAL,length=200,mode="determinate")
pb2.pack(pady=20)
pb2["maximum"] = 100
pb2["value"] = 50
root.mainloop()
Output: