"""PyQt5 教程"""importsysfromPyQt5.QtWidgetsimportQApplication, QWidget, QProgressBar, QPushButtonfromPyQt5.QtCoreimportQBasicTimerclassExample(QWidget):
def__init__(self):
super().__init__()
self.initUI()
definitUI(self):
self.pbar=QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.btn=QPushButton('开始', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction)
self.timer=QBasicTimer()
self.step=0self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('进度条')
self.show()
deftimerEvent(self, e):
ifself.step>=100:
self.timer.stop()
self.btn.setText('完成')
returnself.step=self.step+1self.pbar.setValue(self.step)
defdoAction(self, value):
ifself.timer.isActive():
self.timer.stop()
self.btn.setText('开始')
else:
self.timer.start(100, self)
self.btn.setText('停止')
if__name__=='__main__':
app=QApplication(sys.argv)
ex=Example()
sys.exit(app.exec_())