本文共 1078 字,大约阅读时间需要 3 分钟。
#QComBoximport sysfrom PyQt5.QtWidgets import *from PyQt5.QtCore import *from PyQt5.QtGui import *class QComboxDemo(QWidget): def __init__(self): super(QComboxDemo,self).__init__() self.initUI() def initUI(self): self.setWindowTitle('下拉列表控件') self.resize(300,200) layout= QVBoxLayout() self.label =QLabel('请选择编辑语言') self.cb = QComboBox() self.cb.addItem('C++') self.cb.addItem('Python') self.cb.addItems(['Java',"C#",'Ruby']) self.cb.currentIndexChanged.connect(self.selectChange) layout.addWidget(self.label) layout.addWidget(self.cb) self.setLayout(layout) def selectChange(self,i): self.label.setText(self.cb.currentText()) self.label.adjustSize() for count in range(self.cb.count()): print('item'+str(count)+'='+self.cb.itemText(count)) print('current index', i, 'select changed'+ self.cb.currentText())if __name__ == '__main__': app =QApplication(sys.argv) main = QComboxDemo() main.show() app.exit(app.exec_())
转载地址:http://aoben.baihongyu.com/