【问题标题】:How the comboBox works? [closed]组合框如何工作? [关闭]
【发布时间】:2014-07-03 02:13:12
【问题描述】:

我是 PyQt 的初学者,我放了一个组合框:

    select = QtGui.QComboBox(self)
    select.addItem("San Marcos")
    select.addItem("San Luis")
    select.addItem("San Lucas")
    select.addItem("Rosario I")
    select.addItem("Rosario II")

我如何将每个项目与操作联系起来。例如在终端打印某事。

【问题讨论】:

    标签: python pyqt qcombobox


    【解决方案1】:

    取自here

    import sys
    from PyQt4 import QtGui, QtCore
    
    class Example(QtGui.QWidget):
    
        def __init__(self):
            super(Example, self).__init__()
    
            self.initUI()
    
        def initUI(self):      
    
            self.lbl = QtGui.QLabel("Ubuntu", self)
    
            combo = QtGui.QComboBox(self)
            combo.addItem("Ubuntu")
            combo.addItem("Mandriva")
            combo.addItem("Fedora")
            combo.addItem("Red Hat")
            combo.addItem("Gentoo")
    
            combo.move(50, 50)
            self.lbl.move(50, 150)
    
            combo.activated[str].connect(self.onActivated)        
    
            self.setGeometry(300, 300, 300, 200)
            self.setWindowTitle('QtGui.QComboBox')
            self.show()
    
        def onActivated(self, text):
    
            self.lbl.setText(text)
            self.lbl.adjustSize()  
    
    def main():
    
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      相关资源
      最近更新 更多