在单独的线程中运行 pyQT GUI 主应用程序 [英] Run pyQT GUI main app in seperate Thread

查看:44
本文介绍了在单独的线程中运行 pyQT GUI 主应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to add a PyQt GUI console in my already established application. But the PyQt GUI blocks the whole application making it unable to do rest of the work. I tried using QThread, but that is called from the mainWindow class. What I want is to run the MainWindow app in separate thread.

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 线程,所以我的问题是,以线程形式实现此过程的最佳方法是什么.

My application already uses Python Threads, So my question is, what is the best approach to achieve this process in a threaded form.

推荐答案

一种方法是

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()

这将从您的主应用程序开始,并让您在下面的代码中继续执行您想做的所有其他事情.

this will thread your main application to begin with, and let you carry on with all the other stuff you want to do after in the code below.

这篇关于在单独的线程中运行 pyQT GUI 主应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆