代码语言:javascript复制
1 # -*- coding:utf-8 -*-
2 '''
3 Created on Sep 20, 2018
4
5 @author: SaShuangYiBing
6
7 Comment:
8 '''
9 import sys
10 from PyQt5.QtWidgets import QApplication,QWidget,QComboBox,QLabel
11
12 class New_test(QWidget):
13 def __init__(self):
14 super().__init__()
15 self.initUI()
16
17 def initUI(self):
18 self.lbl = QLabel('fruit',self)
19 combo = QComboBox(self)
20 combo.addItem('apple')
21 combo.addItem('pair')
22 combo.addItem('banana')
23 combo.move(50,50)
24 self.lbl.move(50,150)
25 combo.activated[str].connect(self.onActive)
26
27 self.setGeometry(300,300,300,200)
28 self.setWindowTitle('QCombobox')
29 self.show()
30
31 def onActive(self,text):
32 try:
33 self.lbl.setText(text)
34 self.lbl.adjustSize()
35 except Exception as e:
36 print (e)
37
38 if __name__ == '__main__':
39 app = QApplication(sys.argv)
40 ex = New_test()
41 sys.exit(app.exec_())