繁体   English   中英

在单独的线程中运行pyQT GUI主应用程序

[英]Run pyQT GUI main app in seperate Thread

我试图在我已经建立的应用程序中添加一个PyQt GUI控制台。 但是PyQt GUI阻止了整个应用程序,使其无法完成其余工作。 我尝试使用QThread,但这是从mainWindow类调用的。 我想要在单独的线程中运行MainWindow应用程序。

def main()
      app = QtGui.QApplication(sys.argv)
      ex = Start_GUI()
      app.exec_()  #<---------- code blocks over here !

      #After running the GUI, continue the rest of the application task
      doThis = do_Thread("doThis")
      doThis.start()
      doThat = do_Thread("doThat")
      doThat.start()

我的应用程序已经使用Python线程,所以我的问题是,以线程形式实现此过程的最佳方法是什么。

一种方法是

import threading

def main()
      app = QtGui.QApplication(sys.argv)
      ex = Start_GUI()
      app.exec_()  #<---------- code blocks over here !

#After running the GUI, continue the rest of the application task

t = threading.Thread(target=main)
t.daemon = True
t.start()

doThis = do_Thread("doThis")
doThis.start()
doThat = do_Thread("doThat")
doThat.start()

这将使您的主应用程序开始运行,并让您继续执行下面的代码中要执行的所有其他操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM