PYQT4 UI 线程分离

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time


class Worker(QThread):
    Finish = pyqtSignal(basestring)
    def __init__(self, name, parent=None):
        super(Worker, self).__init__(parent)
        self.name = name
        print self.name
    def run(self):
        #time.sleep(1)
        self.Finish.emit(self.name)


class T(QPushButton):
    def __init__(self):
        super(T, self).__init__()
        self.clicked.connect(self.start_thread)

    def set_data(self, data):
        """
        Work线程运行完成 调用这个函数
        """
        self.setText(data)

    def start_thread(self):
        self.work = Worker(u"线程处理111111", self)
        self.work.Finish.connect(self.set_data)
        self.work.start()


app = QApplication([])

window = T()
window.show()



app.exec_()

你可能感兴趣的:(PYQT4 UI 线程分离)