import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtCore import QCoreApplication class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): quit = QPushButton('退出', self) quit.clicked.connect(QCoreApplication.instance().quit) quit.move(50, 50) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('关闭窗口') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit((app.exec_()))
原文地址:http://blog.csdn.net/u013511642/article/details/45342013