PySide2复选框选中与取消选中事件
作者:YXN-python 阅读量:17 发布日期:2024-10-22
# 创建多个复选框
self.checkbox1 = QCheckBox("选项 1", self)
self.checkbox2 = QCheckBox("选项 2", self)
# 连接每个复选框的stateChanged信号到槽函数
self.checkbox1.stateChanged.connect(self.onStateChanged)
self.checkbox2.stateChanged.connect(self.onStateChanged)
def onStateChanged(self, state):
# 获取发出信号的复选框
checkbox = self.sender()
# 检查复选框是否被选中
if state == Qt.Checked:
print(f"{checkbox.text()} 被选中")
elif state == Qt.Unchecked:
print(f"{checkbox.text()} 被取消选中")
YXN-python
2024-10-22