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 application.
After several hours of looking, I have not found this issue addressed anywhere online. Any explanation and/or work-around would be greatly appreciated. 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): super().__init__() self.initUI() def initUI(self): qbtn = QPushButton('Quit', self) qbtn.clicked.connect(QCoreApplication.instance().quit) qbtn.resize(qbtn.sizeHint()) qbtn.move(50, 50) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Quit button') self.show() #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. # https://stackoverflow.com/questions/40094086/python-kernel-dies-for-second-run-of-pyqt5-gui # Qt does not like more than one QApplication object in the same process. # The "instance()" method retrieves the application instance ("None" if not # already created). if __name__ == "__main__": app = QCoreApplication.instance() if app is None: app = QApplication(sys.argv) # QApp requires the sys arg list. ex = Example() app.exec_() -- 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.