image.png (13.49 KB, 下载次数: 0)
下载附件
2023-2-28 21:35 上传
[Python] 纯文本查看 复制代码import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QGroupBox, QCheckBox, QPushButton
class CheckBox(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(300, 300, 300, 200)
self.vbox = QVBoxLayout()
self.groupbox = QGroupBox("开盒")
self.layout = QVBoxLayout()
self.groupbox.setLayout(self.layout)
self.vbox.addWidget(self.groupbox)
self.btn = QPushButton("全选")
self.btn_1 = QPushButton("反选")
self.btn.clicked.connect(self.quan_xuan)
self.btn_1.clicked.connect(self.fan_xuan)
self.vbox.addWidget(self.btn)
self.vbox.addWidget(self.btn_1)
self.setLayout(self.vbox)
self.setGeometry(300, 300, 300, 200)
for i in range(1, 21):
self.checkbox = QCheckBox(f"{i}")
self.groupbox.layout().addWidget(self.checkbox)
def quan_xuan(self):
for checkbox in self.findChildren(QCheckBox):
checkbox.setChecked(True)
def fan_xuan(self):
for checkbox in self.findChildren(QCheckBox):
checkbox.setChecked(not checkbox.isChecked())
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = CheckBox()
ex.show()
sys.exit(app.exec_())