pyqt5进度条扫光
时间: 2023-08-19 20:06:40 浏览: 113
在 PyQt5 中实现进度条的同步可以通过使用 QThread 或者 QRunnable 来实现。下面是一个使用 QThread 的示例代码:
```python
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QProgressBar
class WorkerThread(QThread):
progress_changed = pyqtSignal(int)
def run(self):
for i in range(101):
self.progress_changed.emit(i)
self.msleep(100) # 模拟耗时操作
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.progress_bar = QProgressBar(self)
self.progress_bar.setRange(0, 100)
self.start_button = QPushButton("Start", self)
self.start_button.clicked.connect(self.start_thread)
self.setCentralWidget(self.progress_bar)
self.addToolBar(self.start_button)
self.worker_thread = WorkerThread()
self.worker_thread.progress_changed.connect(self.on_progress_changed)
def start_thread(self):
self.worker_thread.start()
def on_progress_changed(self, value):
阅读全文