基于python和pyqt5的简易进度条缓冲显示器,可查看进度和用时
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.t=0
self.tt=0
self.step = 0
self.initUI()
def initUI(self):
self.label = QLabel(self)
self.label.setText("用时: ")
self.label.move(40, 15)
self.pbar = QProgressBar(self)
self.pbar.setGeometry(40, 50, 200, 20)
self.btn = QPushButton('开始', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction)
self.timer = QBasicTimer()
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('进度条')
self.show()
def timerEvent(self, e):
if self.step >= 100:
self.step = 0
self.tt=0
self.timer.stop()
self.btn.setText('开始')
return
self.step = self.step+1
self.pbar.setValue(self.step)
self.t=self.t+1
if self.t>=10:
self.t = 0
self.tt=self.tt+1
self.label.setText(str("用时:%d "%int(self.tt)))
def doAction(self, value):
print("do action")
if self.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_())