How to connect a progress bar to a function in Tkinter?

TkinterServer Side ProgrammingProgramming

A Progress Bar helps to visualize the state of a running process. We have used and interacted with many progress bars such as getting the status of downloading a file from the internet, Loading a file on the local system, etc.

Let us suppose that we want to create and connect a progress bar in our application. We will create a full-width progress bar by using ProgressBar(win, options) method. It can be configured through a button that enables and disables it.


#Import the required Libraries
from tkinter import *
from tkinter import ttk
import time

#Create an instance of tkinter frame
win= Tk()

#Set the geometry

#Define a function to Show a Progress Bar
#Create a ProgressBar in a function
def run_progress():
   my_progress= ttk.Progressbar(win, orient= HORIZONTAL, length= 500, mode= 'determinate')
   button.config(state= "disable")

#Create a Button
button=ttk.Button(win, text= "Run",command= run_progress) 340, y= 100)


Now run the above code to display a window that contains a progress bar.


In the given output, if we will click the "Run" Button, it will start running the Progress Bar.

Published on 03-May-2021 09:29:12