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 主应用程序
基础教程推荐
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
