QThread多线程使用方法
QThread多线程使用方法
QThread多线程使用方法
################################ # PyQt5中文网 - PyQt5全套视频教程 # # https://www.PyQt5.cn/ # # 主讲: 村长 # ################################ from PyQt5.Qt import * import sys import time class Threads(QThread): def __init__(self, *argv, **kwargs): super().__init__(*argv, **kwargs) pic_thread = pyqtSignal() def run(self): time.sleep(2) self.pic_thread.emit() class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("多线程 - PyQt5中文网") self.resize(600, 500) self.func_list() def func_list(self): self.func() def func(self): btn = QPushButton('多线程', self) btn.move(30, 30) label = QLabel(self) label.move(80, 80) label.resize(300, 250) label.setStyleSheet('background-color:green') self.label = label thread = Threads(self) # 创建一个子线程 thread.pic_thread.connect(self.aaa) thread.start() # 使用子线程执行run里面的代码 def aaa(self): pixmap = QPixmap('123.jpg') self.label.setPixmap(pixmap) # time.sleep(2) # pixmap = QPixmap('123.jpg') # label.setPixmap(pixmap) # print('WWWW') if __name__ == '__main__': app = QApplication(sys.argv) window = Window() window.show() sys.exit(app.exec_())