Run pyQT GUI main app in seperate Thread(在单独的线程中运行 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 主应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在单独的线程中运行 pyQT GUI 主应用程序
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
