-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
61 lines (47 loc) · 1.75 KB
/
test.py
File metadata and controls
61 lines (47 loc) · 1.75 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
QCheckBox,
QVBoxLayout,
QWidget,
QLabel,
)
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QVBoxLayout()
self.central_widget.setLayout(self.layout)
self.label = QLabel("请选择你的兴趣爱好:", self)
self.layout.addWidget(self.label)
self.checkbox1 = QCheckBox("阅读", self)
self.checkbox1.stateChanged.connect(self.update_label)
self.layout.addWidget(self.checkbox1)
self.checkbox2 = QCheckBox("旅行", self)
self.checkbox2.stateChanged.connect(self.update_label)
self.layout.addWidget(self.checkbox2)
self.checkbox3 = QCheckBox("音乐", self)
self.checkbox3.stateChanged.connect(self.update_label)
self.layout.addWidget(self.checkbox3)
self.checkbox4 = QCheckBox("运动", self)
self.checkbox4.stateChanged.connect(self.update_label)
self.layout.addWidget(self.checkbox4)
def update_label(self):
selected = []
if self.checkbox1.isChecked():
selected.append(self.checkbox1.text())
if self.checkbox2.isChecked():
selected.append(self.checkbox2.text())
if self.checkbox3.isChecked():
selected.append(self.checkbox3.text())
if self.checkbox4.isChecked():
selected.append(self.checkbox4.text())
self.label.setText("你选择的兴趣爱好是:" + ", ".join(selected))
if __name__ == "__main__":
app = QApplication([])
window = MyWindow()
window.show()
app.exec_()