Python - 使用 PyQt 进行线程化

Python - Threading with PyQt

我是 Python 上线程使用的新手,拜托,我需要这方面的帮助。

我正在使用 PyQt,当我使用循环时,主 window 被冻结,直到循环完成。

我在 python 上阅读了有关线程的信息,这似乎是一个解决方案,但我不知道使用我在代码中编写的线程是否很好。

这是我的代码示例。

from Window import *
import sys, threading

class Window(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Window()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.button_download,   QtCore.SIGNAL('clicked()'), start)

print("I'm the main thread")

def start():
    t1 = threading.Thread(target=process)
    t1.start()
    t1.join()

def process():
    for i in range(0, 1000):
        print("I'm the thread:", i)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = Window()
    myapp.show()
    sys.exit(app.exec_())

非常感谢!!

您即将加入话题。如果你想让它在背景上显示 运行,那么删除行

t1.join()