当我们运行一个程序耗时较长时,为了提高客户感知,方便用户知道程序是否在运行,可能就需要使用进度条来提示程序运行状态以及当前运行进度。下面是一个简单的示例,仅供大家参考学习!
""" PyQt5 教程 这个例子显示了一个进度条控件。 作者:CICT天馈TE """ import sys from PyQt5.QtWidgets import QApplication, QWidget, QProgressBar, QPushButton from PyQt5.QtCore import QBasicTimer, Qt class Example(QWidget): def __init__(self): super().__init__() self.setWindowTitle('进度条') self.setGeometry(500, 500, 250, 150) self.initUI() def initUI(self): # 创建界面控件 self.pbar = QProgressBar(self) self.pbar.setGeometry(30, 40, 200, 25) self.timer = QBasicTimer() self.step = 0 self.setGeometry(700, 400, 280, 170) self.btn = QPushButton('开始', self) self.btn.setFocusPolicy(Qt.NoFocus) self.btn.move(40, 80) # 定义槽函数 self.btn.clicked.connect(self.doAction) def timerEvent(self, eve