Python kernel dies for second run of PyQt5 GUI

落花浮王杯 提交于 2019-12-01 03:42:48

This code fixed the problem, thanks for the hint.

app = QtCore.QCoreApplication.instance()
if app is None:
    app = QtWidgets.QApplication(sys.argv)
badsaah6

This works better for the kernel died, restarting error.

from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.QtCore import QCoreApplication

#app = QApplication(sys.argv)
app = QCoreApplication.instance()
if app is None:
    app = QApplication(sys.argv)

For me the above solution worked but only as long as the window-close button (from the Window decoration) was used to close the main window. But the problem still was present when the program was terminated from a GUI signal handler, reacting e.g. to a button being clicked. After much fiddling, I learned that a safe enough way for terminating in this situation is as follows:

def safeExit(self):
    """exit the application gently so Spyder IDE will not hang"""
    self.ui.deleteLater()
    self.ui.close()
    self.ui.destroy()


... self.ui.Button2.clicked.connect(self.safeExit) ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!