this question is related to the code also shown here
An even more down-to-the-point code could be this:
import sys
import os
from PyQt4 import QtGui
class Window(QtGui.QDialog):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
# Just some extra button to mess around
self.button= QtGui.QPushButton('Push Me')
# set the layout
layout = QtGui.QVBoxLayout()
layout.addWidget(self.button)
self.setLayout(layout)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
main = Window()
main.show()
sys.exit(app.exec_())
When I run this, a very silly one-button window appears, which does nothing :-)
Still, when I close it, I get the following complaint from the IPython
console:
An exception has occurred, use %tb to see the full traceback.
To exit: use 'exit', 'quit', or Ctrl-D.
An exception has occurred, use %tb to see the full traceback.
SystemExit: 0
In [3]: %tb
Traceback (most recent call last):
File "<ipython-input-2-0a8f6cad0df5>", line 1, in <module>
runfile('C:/Users/my_username/AppData/Local/Continuum/Anaconda3/Lib/site-packages/PyQt4/SE2.py', wdir='C:/Users/mtk10531/AppData/Local/Continuum/Anaconda3/Lib/site-packages/PyQt4')
File "C:\Users\my_username\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile
execfile(filename, namespace)
File "C:\Users\my_username\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/my_username/AppData/Local/Continuum/Anaconda3/Lib/site-packages/PyQt4/SE2.py", line 39, in <module>
sys.exit(app.exec_())
SystemExit: 0
Then, running again produces the following:
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.
I found other posts complaining about similar things, here and here
I have tried to implement what I understood (not much) from the answers, namely:
to pass the name of my script to
QApplication
:app = QtGui.QApplication(['my_file.py'])
however this had no effectto strip the
app = QtGui.QApplication(['my_file.py'])
from mymain()
, but in this case the Kernel just dies before doing anything else...
Any hint?
Cheers, Michele
P.S. - Just looking at the wavy pattern of \
and /
in the traceback makes me sick!