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 :
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
import time
class Example(QWidget):
def __init__( self ):
super ().__init__()
self .initUI()
def initUI( self ):
self .pbar = QProgressBar( self )
self .pbar.setGeometry( 30 , 40 , 200 , 25 )
self .btn = QPushButton( 'Start' , self )
self .btn.move( 40 , 80 )
self .btn.clicked.connect( self .doAction)
self .setGeometry( 300 , 300 , 280 , 170 )
self .setWindowTitle( "Python" )
self .show()
def doAction( self ):
for i in range ( 101 ):
time.sleep( 0.05 )
self .pbar.setValue(i)
if __name__ = = '__main__' :
App = QApplication(sys.argv)
window = Example()
sys.exit(App. exec ())
|
Output :