This article mainly for you to introduce the PYQT4 implementation of the drop-down menu to choose and print out, with a certain reference value, interested in small partners can refer to
This article for you to share the PYQT4 implementation of the drop-down menu to choose and print out the specific code for your reference, the specific content is as follows
#-*-coding:cp936-*-#QComboBox window component allows the user to select #这个例子中显示一个 qcombobox and a qlabel from the list of lists. The combo box has a list of 5 options, #他们是Linux发行版的名称. The label displays the content selected from the combo box. From PYQT4 import Qtgui, Qtcore class Example (qtgui.qwidget): def __init__ (self): Super (Example, self). __init__ () se Lf.initui () def initui (self): #self. Label = Qtgui.qlabel ("Ubuntu", self) #创建一个 the Qcombobox window component and adds 5 options. Combo = Qtgui.qcombobox (self) combo.additem ("Ubuntu") Combo.additem ("Mandriva") Combo.additem ("Fedora") Combo.additem ("Red Hat") Combo.additem ("Gentoo") Combo.move #self. Label.move (.) #当一个选项被选择, we call Onacti Vated () method. Self.connect (Combo, qtcore.signal (' Activated (QString) '), self.onactivated) Self.setgeometry (250, 200, 350, 250) Self.setwindowtitle (' Qcombobox ') #在该方法中, we set the selection to the label and adjust the size of the label. def onActivated (self, text): Print text #self. Label.settext (text) #self. Label.adjustsize () def main (): app = Qtgui.qa Pplication ([]) ex = Example () ex.show () app.exec_ () if __name__ = = ' __main__ ': Main ()
: