直接上代码,看不懂的可以留言:
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton
from PyQt5.QtCore import QThread, pyqtSignal
import sys
class WorkThread(QThread):
sinOut = pyqtSignal(str)
def __init__(self, obj):
super(WorkThread, self).__init__()
self.obj = obj
def run(self):
if self.obj == "1":
self.run_obj1()
elif self.obj == "2":
self.run_obj2()
else:
pass
def run_obj1(self):
for i in range(5):
self.sinOut.emit("这是obj1第%s次" % i)
self.sleep(1)
def run_obj2(self):
for i in range(5):
self.sinOut.emit("这是obj2第%s次" % i)
self.sleep(2)
class GuiWindow(QWidget):
def __init__(self, parent=None):
super(GuiWindow, self).__init__(parent=parent)
self.resize