PyQt5学习-day1 -4 退出按钮

通常点击右上角 叉号 可以关闭窗口,这里 学习个最基本的 点击退出按钮 退出窗口

 1 import sys
 2 from PyQt5.QtWidgets import QWidget ,QPushButton,QApplication
 3 from PyQt5.QtCore import QCoreApplication
 4 
 5 class Example(QWidget):
 6     def __init__(self):
 7         super().__init__()
 8         self.initUI()
 9 
10     def initUI(self):
11         qbtn = QPushButton('退出',self)
12         qbtn.clicked.connect(QCoreApplication.instance().quit)
13         #按钮的默认尺寸
14         qbtn.resize(qbtn.sizeHint())
15         qbtn.move(50,50)
16 
17         self.setGeometry(300,300,300,150)
18         self.setWindowTitle('标题 退出')
19         self.show()
20 
21 if __name__ == '__main__':
22     app = QApplication(sys.argv)
23     ex = Example()
24     sys.exit(app.exec_())

posted on 2018-03-07 09:49  jiayou888888  阅读(323)  评论(0编辑  收藏  举报

导航