
import tkinter as tk
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")
def my_fun(type): # update the value of progress bar
if(type=='+'):
prg1['value'] += 10 # increase value
else:
prg1['value'] -= 10 # decrease value
l1.config(text=str(prg1['value'])) #update Label
prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
length = 300, mode = 'determinate')
prg1.place(relx=.1,rely=.3)
b1=tk.Button(my_w,text='Move +',command=lambda: my_fun('+'))
b1.place(relx=0.3,rely=0.5)
b2=tk.Button(my_w,text='Move -',command=lambda: my_fun('-'))
b2.place(relx=0.5,rely=0.5)
font1=('times',24,'normal')
l1=tk.Label(my_w,text='value here',font=font1)
l1.place(relx=0.4,rely=0.01)
my_w.mainloop() # Keep the window open
We used the following options of progress bar

prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
length = 300, mode = 'indeterminate')
| 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. |
def my_fun(type): # update the value of progress bar
if(type=='+' and prg1['value']<100): # Upper limit is 100
prg1['value'] += 10 # increase value
elif(type=='-' and prg1['value']>0): # Lower limit is 0
prg1['value'] -= 10 # decrease value
l1.config(text=str(prg1['value'])) #update Label
def my_fun(type): # update the value of progress bar
if(type=='+' and prg1['value']<100): # Upper limit is 100
prg1['value'] += 10 # increase value
elif(type=='-' and prg1['value']>0): # Lower limit is 0
prg1['value'] -= 10 # decrease value
l1.config(text=str(prg1['value'])) #update Label
if prg1['value']==prg1['maximum']:
my_w.destroy()
Full code is here.
import tkinter as tk
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")
def my_fun(type): # update the value of progress bar
if(type=='+' and prg1['value']<100): # Upper limit is 100
prg1['value'] += 10 # increase value
elif(type=='-' and prg1['value']>0): # Lower limit is 0
prg1['value'] -= 10 # decrease value
l1.config(text=str(prg1['value'])) #update Label
if prg1['value']==prg1['maximum']:
my_w.destroy()
prg1 = ttk.Progressbar(my_w,orient = HORIZONTAL,
length = 300, mode = 'determinate',maximum=100)
prg1.place(relx=.1,rely=.3)
b1=tk.Button(my_w,text='Move +',command=lambda: my_fun('+'))
b1.place(relx=0.3,rely=0.5)
b2=tk.Button(my_w,text='Move -',command=lambda: my_fun('-'))
b2.place(relx=0.5,rely=0.5)
font1=('times',24,'normal')
l1=tk.Label(my_w,text='value here',font=font1)
l1.place(relx=0.4,rely=0.01)
my_w.mainloop() # Keep the window open
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.