After running the program in the background, when I execute I get (Not responding in the title bar).
And if I try to close it shows this
And after closing it start giving kernel killing message as shown in the screen on the right side.
I am running "Anaconda-2.3.0-Windows-x86_64". Please tell me what to do.
Spyder does some weird things where it doesn't run code in a new process and so it can keep things around from the last time the code was run. Quite frankly I would find this extremely annoying, and so I don't use Spyder (which means this answer is potentially not perfect, and someone else should probably post another with a better solution!)
What you need to do is check to see if the QApplication
already exists, and only create it if does not.
if QApplication.instance():
app = QApplication.instance()
else:
app = QApplication(sys.argv)
...
app.exec_()
I think you should always be calling app.exec_()
, regardless of whether the QApplication
has been created before.
Personally though, I launch python files from a standard windows command line so that I always know it is starting fresh.
You just need to add this: app.exec_() at the end of the code
import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.setGeometry(50,50,500,300)
window.setWindowTitle("PyQt Ecuador")
window.show()
app.exec_()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.