I'm new to PyQt5 and I've got an error (pythonw.exe not working anymore) with the following code:
import sys from PyQt5.QtWidgets import QWidget, QPushButton, QApplication from PyQt5.QtCore import QCoreApplicationclass Example(QWidget):
def __init__(self): super().__init__() self.initUI() def initUI(self): qbtn = QPushButton('Quit', self) qbtn.clicked.connect(self.q) qbtn.resize(qbtn.sizeHint()) qbtn.move(50, 50) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Quit button') self.show() def q(): print('test') sys.exit()if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() app.exec_()
First it works, but only until I push the "quit" button. Then the error message pops up. If I put the q() function outside the class (and change "self.q" into "q") it works fine. What's the problem?
Thanks in advance.
Windows 7 Python 3.4.3 (x86) PyQt 5.5.1 (x86)