PyQt5--CloseWindow

 1 # -*- coding:utf-8 -*-
 2 '''
 3 Created on Sep 13, 2018
 4 
 5 @author: SaShuangYiBing
 6 '''
 7 import sys
 8 from PyQt5.QtWidgets import QApplication,QWidget,QPushButton
 9 from PyQt5.QtCore import QCoreApplication
10 
11 class New_test(QWidget):
12     def __init__(self):
13         super().__init__()
14         self.initUI()
15         
16     def initUI(self):
17         qbtn = QPushButton('Quit',self) # 创建了一个按钮。按钮是一个QPushButton类的实例。
18         # 构造方法的第一个参数是显示在button上的标签文本。第二个参数是父组件。
19         # 父组件是New_test组件,它继承了QWiget类。
20         qbtn.clicked.connect(QCoreApplication.instance().quit)
21         qbtn.resize(qbtn.sizeHint())
22         qbtn.move(90,50)
23         
24         self.setGeometry(300,300,250,150)
25         self.setWindowTitle('Quit')
26         self.show()
27         
28 if __name__ == "__main__":
29     app = QApplication(sys.argv)
30     ex = New_test()
31     sys.exit(app.exec_())        

点击 quit 按钮退出该窗口

 

posted @ 2018-09-13 17:24  iSZ  阅读(574)  评论(0编辑  收藏  举报