import tkinter as tk
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")
prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
value=70,length = 300, mode = 'determinate')
prg1.place(relx=.1,rely=.2)
my_w.mainloop() # Keep the window open
Options | Details |
---|---|
orient | Orientation of the Progress bar. Values are Horizontal or Vertical |
length | Length of the Progress bar, (width if horizontal, height if vertical) |
mode | Values can be determinate OR indeterminate Check the examples |
maximum | Default value is 100, specifies the maximum value. |
value | The current value of the Progress bar. Can be set or read. |
variable | Variable can be linked to value of Progress Bar. Realtime changes ( in values ) can be captured. |
Method | Details |
---|---|
start( interval ) | increment the Progress bar in every interval value (50 milliseconds default ) |
step( amount ) | Default is 1 if omitted, increments in the progress bar value by given amount |
stop() | Stop the autoincrement mode. |
my_dict=ttk.Progressbar(prg1)
print(my_dict['orient']) # print the value of orient
print(my_dict['mode']) # value of mode
import tkinter as tk
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")
def my_upd(value):
prg1['value'] =my_scale1.get()
prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
length = 320, mode = 'determinate',maximum=100)
prg1.grid(row=0,column=0,padx=20,pady=45)
my_scale1 = tk.Scale(my_w, from_=0, to=100, orient='horizontal'
,command=my_upd,length=200)
my_scale1.grid(row=1,column=0)
my_w.mainloop()
s = ttk.Style()
s.theme_use('alt')
s.configure("yellow.Horizontal.TProgressbar", background='yellow')
prg1=ttk.Progressbar(my_w,length=320,mode='determinate',maximum=100,value=75,
style='yellow.Horizontal.TProgressbar')
We can integrate Button click event to update the colour of the progress bar. Here we are using config() to update the style property of the Progress bar. import tkinter as tk
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x300")
s = ttk.Style()
s.theme_use('alt')
s.configure("red.Horizontal.TProgressbar", background='red')
s.configure("yellow.Horizontal.TProgressbar", background='yellow')
s.configure("green.Horizontal.TProgressbar", background='green')
l1=tk.Label(my_w,text='Changing style of Progress bar',font=16,bg='yellow')
l1.grid(row=0,column=0,columnspan=3,pady=15)
prg1=ttk.Progressbar(my_w,length=320,mode='determinate',maximum=100,value=75,
style='yellow.Horizontal.TProgressbar')
prg1.grid(row=1,column=0,columnspan=3,padx=20,pady=45)
def my_upd(value): # update the progress bar using scale input
prg1['value'] =my_scale1.get()
b1=tk.Button(my_w,text='Red',bg='red',font=20,
command=lambda:prg1.config(style='red.Horizontal.TProgressbar'))
b1.grid(row=2,column=0)
b2=tk.Button(my_w,text='Yellow',bg='yellow',font=20,
command=lambda:prg1.config(style='yellow.Horizontal.TProgressbar'))
b2.grid(row=2,column=1)
b3=tk.Button(my_w,text='Green',bg='lightgreen',font=20,
command=lambda:prg1.config(style='green.Horizontal.TProgressbar'))
b3.grid(row=2,column=2)
my_scale1 = tk.Scale(my_w, from_=0, to=100, orient='horizontal'
,command=my_upd,length=200)
my_scale1.set(75) # default value of slider kept at 75
my_scale1.grid(row=3,column=0,columnspan=3)
my_w.mainloop()
ProgressBar showing number of chars entered in a Text widget Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.