QProgressBar is a widget to show process. You’ve likely seen it many times during installations.

The widget shows a bar and you can see the percentage completed. You can set its value with
the method setValue(). Where 50 would set it to 50%.

Related Course:
PyQt Desktop Apps with Python

QProgressBar

Progressbar

Use the code below to create a progressbar:

1
2
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)

You can set the value with:

1
self.pbar.setValue(50)

That’s all that’s needed to create a progressbar.

To update it’s value, you can use a QTimer.

1
from PyQt5.QtCore import QBasicTimer

Call a method every second with these lines:

1
2
self.timer = QTimer()        self.timer.timeout.connect(self.handleTimer)
self.timer.start(1000)

Then update the progressbar value:

1
2
3
4
5
6
7
8
def handleTimer(self):
value = self.pbar.value()
if value < 100:
value = value + 1
self.pbar.setValue(value)
else:
self.timer.stop()

progressbar pyqt

Example

Copy the code below to see a progressbar counting from 50% to 100%.
The progressbar is updated using the method handleTimer() and a QTimer().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow, QProgressBar
from PyQt5.QtCore import Qt

class Example(QMainWindow):

def __init__(self):
super().__init__()

self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.pbar.setValue(50)

self.setWindowTitle("QT Progressbar Example")
self.setGeometry(32,32,320,200)
self.show()

self.timer = QTimer()
self.timer.timeout.connect(self.handleTimer)
self.timer.start(1000)

def handleTimer(self):
value = self.pbar.value()
if value < 100:
value = value + 1
self.pbar.setValue(value)
else:
self.timer.stop()


if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

Download Examples