Создаю два ProgressBar'a, которые заполняются в 2 потока при нажатии кнопки Start.
from PyQt5.QtWidgets import QWidget, QProgressBar, QPushButton, QApplication
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.firstProgressBar = QProgressBar(self)
self.firstProgressBar.setGeometry(25, 25, 400, 40)
self.firstStep = 0
self.secondProgressBar = QProgressBar(self)
self.secondProgressBar.setGeometry(25, 100, 400, 40)
self.secondStep = 0
self.button = QPushButton("Start", self)
self.button.setGeometry(420, 25, 160, 40)
self.setGeometry(300, 300, 600, 165)
if __name__ == '__main__':
import sys
from threading import Thread
Application = QApplication(sys.argv)
ex = Example()
ex.show()
def function(pbNumber, k):
for i in range(k * 1001):
sum([i * i for i in range(5000)])
if pbNumber == 1:
ex.firstStep = i // (k * 10)
ex.firstProgressBar.setValue(ex.firstStep)
else:
ex.secondStep = i // (k * 10)
ex.secondProgressBar.setValue(ex.secondStep)
def action():
Thread(target=function, args=(1, 1)).start()
Thread(target=function, args=(2, 2)).start()
ex.button.clicked.connect(action)
sys.exit(Application.exec())