PyQt5--CloseWindow

时间:2023-03-09 08:41:48
PyQt5--CloseWindow
 # -*- coding:utf-8 -*-
'''
Created on Sep 13, 2018 @author: SaShuangYiBing
'''
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QPushButton
from PyQt5.QtCore import QCoreApplication class New_test(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
qbtn = QPushButton('Quit',self) # 创建了一个按钮。按钮是一个QPushButton类的实例。
# 构造方法的第一个参数是显示在button上的标签文本。第二个参数是父组件。
# 父组件是New_test组件,它继承了QWiget类。
qbtn.clicked.connect(QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(90,50) self.setGeometry(300,300,250,150)
self.setWindowTitle('Quit')
self.show() if __name__ == "__main__":
app = QApplication(sys.argv)
ex = New_test()
sys.exit(app.exec_())

点击 quit 按钮退出该窗口

PyQt5--CloseWindow