PyQt5--QComboBox

时间:2023-03-09 18:02:36
PyQt5--QComboBox
 # -*- coding:utf-8 -*-
'''
Created on Sep 20, 2018 @author: SaShuangYiBing Comment:
'''
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QComboBox,QLabel class New_test(QWidget):
def __init__(self):
super().__init__()
self.initUI() def initUI(self):
self.lbl = QLabel('fruit',self)
combo = QComboBox(self)
combo.addItem('apple')
combo.addItem('pair')
combo.addItem('banana')
combo.move(50,50)
self.lbl.move(50,150)
combo.activated[str].connect(self.onActive) self.setGeometry(300,300,300,200)
self.setWindowTitle('QCombobox')
self.show() def onActive(self,text):
try:
self.lbl.setText(text)
self.lbl.adjustSize()
except Exception as e:
print (e) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = New_test()
sys.exit(app.exec_())

PyQt5--QComboBox