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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With