标签:radio pen argv qwidget led rem check resize etc
ButtonGroup即按钮组;提供一个按钮容器,可以将多个按钮划分为一组
案例
from PyQt5.Qt import * import sys app = QApplication(sys.argv) window = QWidget() window.setWindowTitle("按钮组的使用") window.resize(500, 500) # 男女 r_male = QRadioButton("男", window) r_female = QRadioButton("女", window) r_male.move(100, 100) r_female.move(100, 150) r_male.setChecked(True) # 1.创建按钮组 sex_group = QButtonGroup(window) # 2.添加按钮 sex_group.addButton(r_male, 1) sex_group.addButton(r_female, 2) # 是否 r_yes = QRadioButton("是", window) r_no = QRadioButton("否", window) r_yes.move(300, 100) r_no.move(300, 150) answer_group = QButtonGroup(window) answer_group.addButton(r_yes) answer_group.addButton(r_no) answer_group.setId(r_yes, 1) # 设置按钮组按钮ID answer_group.setId(r_no, 2) print(answer_group.id(r_yes)) print(answer_group.id(r_no)) r_no.setChecked(True) # 默认选中 print(answer_group.checkedId()) # sex_group.setExclusive(False) # 设置排他性 # sex_group.removeButton(r_female) # 移除按钮 def test(val): # print(val) print(sex_group.id(val)) sex_group.buttonClicked.connect(test) # 信号 # sex_group.buttonPressed.connect(test) # sex_group.buttonReleased.connect(test) # sex_group.buttonToggled.connect() # sex_group.buttonClicked[int].connect(test) #可以传按钮ID window.show() sys.exit(app.exec_())
标签:radio pen argv qwidget led rem check resize etc
原文地址:https://www.cnblogs.com/mosewumo/p/12515202.html