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 主应用程序
基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
