PyQt5--QProgressBar

时间:2021-12-29 09:50:02
 # -*- coding:utf-8 -*-
'''
Created on Sep 20, 2018 @author: SaShuangYiBing Comment:
'''
import sys
from PyQt5.QtCore import QBasicTimer
from PyQt5.QtWidgets import QApplication,QWidget,QProgressBar,QPushButton class New_test(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(75,80)
self.btn.clicked.connect(self.doAction) self.timer = QBasicTimer()
self.step = 0 self.setGeometry(300,300,280,170)
self.setWindowTitle('QProgress Bar')
self.show() def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
self.btn.setText('Finished')
return
self.step += 1
self.pbar.setValue(self.step) def doAction(self,e):
if self.timer.isActive():
self.timer.stop()
self.btn.setText('Start')
else:
self.timer.start(100,self)
self.btn.setText('Stop') if __name__ == '__main__':
app = QApplication(sys.argv)
ex = New_test()
sys.exit(app.exec_())

PyQt5--QProgressBar

PyQt5--QProgressBar

PyQt5--QProgressBar