Python PyQt4:制作切换单选按钮,在同一窗口上打开不同的组合框

Python PyQt4:制作切换单选按钮,在同一窗口上打开不同的组合框,python,combobox,pyqt4,Python,Combobox,Pyqt4,我正在QTabWidget中创建一个功能,它将: 允许用户切换个人想要执行分析的单选按钮(2个选项) 根据切换的单选按钮,在单选按钮下方添加某些组合框 在组合框之间创建依赖关系 按下“重置参数”按钮时,所有参数都将重置 我能够使“重置参数”在大多数情况下都能正常工作,其中它不改变两个单选按钮&组合框之间的依赖关系可以自行工作。但我不知道如何定义可以将所选组合框添加到先前定义的网格布局的函数。此外,不确定选项卡名称的笨拙下拉菜单来自何处/为什么 代码是使用Python 2.7从Anaconda输入

我正在QTabWidget中创建一个功能,它将:

  • 允许用户切换个人想要执行分析的单选按钮(2个选项)
  • 根据切换的单选按钮,在单选按钮下方添加某些组合框
  • 在组合框之间创建依赖关系
  • 按下“重置参数”按钮时,所有参数都将重置
  • 我能够使“重置参数”在大多数情况下都能正常工作,其中它不改变两个单选按钮&组合框之间的依赖关系可以自行工作。但我不知道如何定义可以将所选组合框添加到先前定义的网格布局的函数。此外,不确定选项卡名称的笨拙下拉菜单来自何处/为什么

    代码是使用Python 2.7从Anaconda输入到iPython笔记本中的

    #7.5.2016 making toggle switches
    
    import sys
    import webbrowser
    from PyQt4 import QtGui, QtCore
    
    QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Plastique'))
    
    class BeginExplorerWidget(QtGui.QTabWidget):
        def __init__(self, parent=None):
            super(BeginExplorerWidget, self).__init__(parent)
            self.setGeometry(50,50,800,600)
            self.setWindowTitle("Explorer")
    
            #Defining items inside the tabs
    
            #tab 1: ProQinase Cancer Cell Line Explorer
            button = QtGui.QPushButton("Reset parameters")
            button.clicked.connect(self.my_method)        
            self.rad1 = QtGui.QRadioButton("Explore Individual Cell Lines")
            self.rad1.toggled.connect(lambda: self.btnstate(self.rad1))
            self.rad2 = QtGui.QRadioButton("Cell Line Correlation")
            self.rad2.toggled.connect(lambda: self.btnstate(self.rad2))
    
            #opens if rad1 on
            self.combo1 = QtGui.QComboBox(self)
            self.list1 = ['x', 'y', 'z']
            self.combo1.addItems(QtCore.QStringList(self.list1))
            self.combo1.currentIndexChanged.connect(self.changeindexcombo1)
            self.combo2 = QtGui.QComboBox(self)
            self.list2 =[['x1', 'x2', 'x3'], ['y1', 'y2', 'y3'], ['z1', 'z2', 'z3']]
            self.combo2.addItems(QtCore.QStringList(self.list2[0]))
    
            #opens if rad2 on
            self.comboA = QtGui.QComboBox(self)
            self.listA = ['CPQ #', 'CCLE #']
            self.comboA.currentIndexChanged.connect(self.changeindexcomboA)
            self.comboB = QtGui.QComboBox(self)
            self.listB = [['Q1', 'Q2', 'Q3'], ['C1', 'C2', 'C3']]
            self.comboC = QtGui.QComboBox(self)
            self.listC = ['CPQ #', 'CCLE #']
            self.comboC.currentIndexChanged.connect(self.changeindexcomboC)
            self.comboD = QtGui.QComboBox(self)
            self.listD = [['Q1', 'Q2', 'Q3'], ['C1', 'C2', 'C3']]
    
            tab1 = QtGui.QWidget()  
    
            #layouts:        
            #tab 1: ProQinase Cancer Cell Line Explorer
            layout = QtGui.QGridLayout()
            layout.addWidget(button, 0,0)
            layout.addWidget(self.rad1, 0,1)
            layout.addWidget(self.rad2, 0,2)
            tab1.setLayout(layout)
    
            self.group = QtGui.QButtonGroup()
            self.group.addButton(self.rad1)
            self.group.addButton(self.rad2)
    
            #adding tabs to the QtGui.QTabWidget
            self.addTab(tab1,"ProQinase Cancer Cell Lines")
    
            self.show()
    
        def my_method(self):
            self.group.setExclusive(False)
            self.rad1.setChecked(False)
            self.rad2.setChecked(False)
            self.group.setExclusive(True)
    
        def btnstate(self, rad):
            if rad.text() == "Explore Individual Cell Lines":
                self.tab1.addWidget(self.combo1, 1, 1)
                self.tab1.addWidget(self.combo2, 1, 2)       
            if rad.text() == "Cell Line Correlation":
                #layout = QtGui.QGridLayout()
                self.tab1.addWidget(self.comboA, 1, 1)
                self.tab1.addWidget(self.comboB, 1, 2)
                self.tab1.addWidget(self.comboC, 2, 1)
                self.tab1.addWidget(self.comboD, 2, 2)
                #tab1.setlayout(layout)
    
        def changeindexcombo1(self, ind):
            self.combo2.clear()
            self.combo2.addItems(QtCore.QStringList(self.list2[ind]))
    
        def changeindexcomboA(self, ind):
            self.comboB.clear()
            self.comboB.addItems(QtCore.QStringList(self.list2[ind]))
    
        def changeindexcomboC(self, ind):
            self.comboD.clear()
            self.comboD.addItems(QtCore.QStringList(self.list2[ind]))
    
    if __name__ == '__main__':
        app = QtGui.QApplication([])
        window = BeginExplorerWidget()
        window.show()
        app.exec_()