import sys
#带入系统
from PyQt5.QtWidgets import *
class quitapp(QMainWindow):
def __init__(self,parent=None):
super(quitapp,self).__init__(parent)
#初始化
self.setWindowTitle('退出程序')
self.resize(600,600)
#获取创建一个Button
self.button1 = QPushButton("退出")
#链接单击事件
self.button1.clicked.connect(self.onclik)
hlay = QHBoxLayout()
hlay.addWidget(self.button1)
mainfram = QWidget()
mainfram.setLayout(hlay)
self.setCentralWidget(mainfram)
# 单击事件方法 自定义的槽
def onclik(self):
sender = self.sender()
print(sender.text()+'!')
app = QApplication.instance()
app.quit()
if __name__ =="__main__":
qapp = QApplication(sys.argv)
main = quitapp()
main.show()
sys.exit(qapp.exec_())