PyQt5 QProgressBar – How to create progress bar ?

In this article we will see how we can create the progress bar in PyQt5. In order to create progress bar object we will use QProgressBar.

A progress bar is a graphical control element used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation. Sometimes, the graphic is accompanied by a textual representation of the progress in a percent format.

Syntax :

pbar = QProgressBar(self)

Code :

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
import time
  
class Example(QWidget):
  
    def __init__(self):
        super().__init__()
  
        # calling initUI method
        self.initUI()
  
    # method for creating widgets
    def initUI(self):
  
        # creating progress bar
        self.pbar = QProgressBar(self)
  
        # setting its geometry
        self.pbar.setGeometry(30, 40, 200, 25)
  
        # creating push button
        self.btn = QPushButton('Start', self)
  
        # changing its position
        self.btn.move(40, 80)
  
        # adding action to push button
        self.btn.clicked.connect(self.doAction)
  
        # setting window geometry
        self.setGeometry(300, 300, 280, 170)
  
        # setting window action
        self.setWindowTitle("Python")
  
        # showing all the widgets
        self.show()
  
    # when button is pressed this method is being called
    def doAction(self):
  
        # setting for loop to set value of progress bar
        for i in range(101):
  
            # slowing down the loop
            time.sleep(0.05)
  
            # setting value to progress bar
            self.pbar.setValue(i)
  
# main method
if __name__ == '__main__':
      
      
    # create pyqt5 app
    App = QApplication(sys.argv)
  
    # create the instance of our Window
    window = Example()
  
    # start the app
    sys.exit(App.exec())

chevron_right


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.