I'm new to PyQt, and I'm following the tutorial at 
http://zetcode.com/gui/pyqt5/firstprograms/ to build a GUI with a "Quit" 
push button. When I run it from Spyder, the Quit button doesn't work and 
Spyder locks up. I must restart the kernel to recover. However, when I run 
this code from the python command line directly, it works just fine and 
clicking on the "Quit" button closes the window and terminates the 

After several hours of looking, I have not found this issue addressed 
anywhere online. Any explanation and/or work-around would be greatly 

I am running Windows 10 Home Edition (64b), and using Python 3.5.3, Spyder 
3.2 and Qt5.5.1.

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication

class Example(QWidget):
    def __init__(self):
    def initUI(self):               
        qbtn = QPushButton('Quit', self)
        qbtn.move(50, 50)       
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Quit button')    
#if __name__ == '__main__':
#    app = QApplication(sys.argv)
#    ex = Example()
#    sys.exit(app.exec_())

   # The following "if" logic keeps the kernal from dying every other time.
    # Qt does not like more than one QApplication object in the same 
    # The "instance()" method retrieves the application instance ("None" if 
    # already created).

if __name__ == "__main__":
     app = QCoreApplication.instance()
    if app is None:
        app = QApplication(sys.argv) # QApp requires the sys arg list.

    ex = Example()


You received this message because you are subscribed to the Google Groups 
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to spyderlib+unsubscr...@googlegroups.com.
To post to this group, send email to spyderlib@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to