单击pushButton创建一个ComboBox

时间:2016-06-27 17:16:53

标签: python-2.7 pyqt4 qcombobox qpushbutton

我想通过点击按钮创建一个组合框。

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        self.Dialog=Dialog
        self.Dialog.setObjectName(_fromUtf8("Dialog"))
        self.Dialog.resize(681, 408)

        self.pushButton = QtGui.QPushButton(self.Dialog)
        self.pushButton.setGeometry(QtCore.QRect(400, 290, 75, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))

class Window(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui=Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.pushButton.clicked.connect(self.browse)

    def browse(self):
        self.ui.comboBox=QtGui.QComboBox(self.ui.Dialog)
        self.ui.comboBox.setObjectName(_fromUtf8("comboBox"))
        self.ui.comboBox.addItem(_fromUtf8(""))
        self.ui.comboBox.setGeometry(QtCore.QRect(100, 100, 100, 100))
if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    dlg = Window()
    dlg.show()
    app.exec_()

当我运行代码并单击按钮时,没有任何反应。我忘记某处/某处出错了吗?

0 个答案:

没有答案