关闭 PyQt4 Gui 应用程序后 Python 内核崩溃 [英] Python Kernel crashes after closing an PyQt4 Gui Application

查看:45
本文介绍了关闭 PyQt4 Gui 应用程序后 Python 内核崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我的问题:

我想创建一个 PyQt4 Gui,它可以从 python 控制台执行(用 IDLE、Spyder 控制台和 IPython 控制台测试),然后允许用户更改和查看变量.关闭应用程序后,用户应该能够在控制台中使用变量做进一步的工作.但是通过关闭 Gui 内核崩溃并且无法对控制台进行任何新的输入.

I want to create a PyQt4 Gui, which can be executed from a python console (tested with IDLE, Spyder Console and IPython Console) and then allows the user to change and view variables. After closing the app the user should be able to do further work with the variables in the console. But by closing the Gui the Kernel crashes and it is not possible to make any new input to the console.

我正在使用 Python 2.7 和 PyQt4.我正在使用以下代码启动关闭应用程序:

I'm working with Python 2.7 and PyQt4. I am using the following code to start an close the application:

app=QtGui.QApplication(sys.argv)
MainApp=plottest()
MainApp.show()
sys.exit(app.exec_())

推荐答案

这里的简单解决方案 https://www.reddit.com/r/learnpython/comments/45h05k/solved_kernel_crashing_when_closure_gui_spyder/

只放

if __name__ == "__main__":
    app=0           #This is the solution
    app = QtGui.QApplication(sys.argv)
    MainApp = Dice_Roller()
    MainApp.show()
    sys.exit(app.exec_())

这篇关于关闭 PyQt4 Gui 应用程序后 Python 内核崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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