Skip to content

Instantly share code, notes, and snippets.

@akiross
Created January 21, 2019 20:27
Show Gist options
  • Save akiross/0259be0586d7ece7e1f885f0e2bca1ee to your computer and use it in GitHub Desktop.
Save akiross/0259be0586d7ece7e1f885f0e2bca1ee to your computer and use it in GitHub Desktop.
PyQt5 Threading Demo
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