-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuitApplication.py
36 lines (28 loc) · 1004 Bytes
/
QuitApplication.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from PyQt5.QtWidgets import QHBoxLayout, QMainWindow, QApplication, QWidget, QPushButton
class QuitApplication(QMainWindow):
def __init__(self):
super(QuitApplication, self).__init__()
self.resize(300, 120)
self.setWindowTitle('退出应用程序')
# 添加button
self.button1 = QPushButton('退出应用程序')
# 将信号与槽关联
self.button1.clicked.connect(self.onClick_Button)
layout = QHBoxLayout()
layout.addWidget(self.button1)
mainFrame = QWidget()
mainFrame.setLayout(layout)
self.setCentralWidget(mainFrame)
# 按钮单击事件的方法
def onClick_Button(self):
sender = self.sender()
print(sender.text() + '按钮被按下')
app = QApplication.instance()
# 退出应用程序
app.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QuitApplication()
main.show()
sys.exit(app.exec_())