gui1.py:
<块引用>import sys from PyQt5.QtWidgets import QApplication, QWidget应用程序 = QApplication(sys.argv)w = QWidget()w.resize(250,150) w.show()#sys.exit(app.exec_())app.exec_()
IPhython 日志:
runfile('F:/work/ws_python/TestProj1/gui1/gui1.py', wdir='F:/work/ws_python/TestProj1/gui1')runfile('F:/work/ws_python/TestProj1/gui1/gui1.py', wdir='F:/work/ws_python/TestProj1/gui1')内核死机,重启内核死机,重启内核死机,重启
为什么内核在第二次运行时死机以及如何解决?
<块引用>(即使在最后一行使用 #sys.exit(app.exec_()) 也是如此.)
此代码解决了问题,感谢提示.
app = QtCore.QCoreApplication.instance()如果应用程序是无:应用程序 = QtWidgets.QApplication(sys.argv)
gui1.py:
import sys from PyQt5.QtWidgets import QApplication, QWidget app = QApplication(sys.argv) w = QWidget() w.resize(250,150) w.show() #sys.exit(app.exec_()) app.exec_()
IPhython log:
runfile('F:/work/ws_python/TestProj1/gui1/gui1.py', wdir='F:/work/ws_python/TestProj1/gui1')
runfile('F:/work/ws_python/TestProj1/gui1/gui1.py', wdir='F:/work/ws_python/TestProj1/gui1')
Kernel died, restarting
Kernel died, restarting
Kernel died, restarting
Why kernel dies for 2nd run and how to solve it?
(Doing the same even using #sys.exit(app.exec_()) as last line.)
This code fixed the problem, thanks for the hint.
app = QtCore.QCoreApplication.instance()
if app is None:
app = QtWidgets.QApplication(sys.argv)
这篇关于Python 内核因 PyQt5 GUI 的第二次运行而死机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!