单选按钮网格

时间:2015-01-13 20:30:04

标签: python user-interface grid radio-button

背景故事:我是编写GUI的新手,我正在尝试制作一个单选按钮网格。到目前为止,我有这个但是由于某种原因,当我传入参数时,它会点击“self.radio_button_list [0] = setChecked。(True)”行,然后抛出一个列表索引超出范围错误。知道为什么会这样,以及如何解决它?是否有更好的方法来制作单选按钮网格(或下拉菜单,有51个选项)?

我用行初始化:

self.radio_button_widget = RadioButtonWidget('File Types', "Please select the type of file to edit", ('adhdrs_on_bd', 'adhdrs_on_bm', 'alabama', 'asr', 'atq', 'bsa', 'caars_on_bd'))

然后调用:

from PyQt4 import *  
class RadioButtonWidget(QtGui.QWidget):  
    def __init__(self, label, instruction, button_list):  
        super(RadioButtonWidget,self).__init__()  
        self.titleLabel = QtGui.QLabel(label)  
        self.radio_group_box= QtGui.QGroupBox(instruction)  
        self.radio_button_group = QtGui.QButtonGroup()  

        self.radio_button_list = []  
        for each in self.radio_button_list:  
            self.radio_button_list.append(QtGui.QRadioButton(each))


        self.radio_button_list[0].setChecked(True) 

        self.radio_button_layout = QtGui.QVBoxLayout()

        counter = 1
        for each in self.radio_button_list:
            self.radio_button_layout.addWidget(each)
            self.radio_button_group.addButton(each)
            self.radio_button_group.setID(each, counter)
            counter += 1
        self.radio_group_box.setLayout(self.radio_button_layout)


        self.main_layout = QtGui.QVBoxLayout()
        self.main_layout.addWidget(self.titleLabel)
        self.main_layout.addWidget(self.radio_group_box)
        self.setLayout(self.main_layout)




    def selected_button(self):
        return self.radio_button_group.checkedId()

0 个答案:

没有答案