Created
January 21, 2019 20:27
-
-
Save akiross/0259be0586d7ece7e1f885f0e2bca1ee to your computer and use it in GitHub Desktop.
PyQt5 Threading Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from itertools import count | |
from PyQt5 import QtCore, QtWidgets | |
class Worker(QtCore.QThread): | |
data_ready = QtCore.pyqtSignal(str) | |
def __init__(self): | |
super().__init__() | |
def run(self): | |
time.sleep(5) | |
for i in count(1): | |
self.data_ready.emit(f"Iteration number {i}") | |
time.sleep(1) | |
if __name__ == '__main__': | |
app = QtWidgets.QApplication(sys.argv) | |
label = QtWidgets.QLabel("Waiting data...") | |
work = Worker() | |
work.data_ready.connect(label.setText) | |
work.start() | |
label.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment