QComboBox下拉列表框
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class MyComboBoxWindow(QWidget):
def __init__(self, parent=None):
super(MyComboBoxWindow, self).__init__(parent)
self.setWindowTitle("ComBox Demo")
self.resize(300, 100)
layout = QVBoxLayout()
self.lb1 = QLabel("")
self.cb = QComboBox()
self.cb.addItem("C")
self.cb.addItem("C++")
self.cb.addItems(["Java", "C#", "Python"])
self.cb.currentIndexChanged.connect(self.selectionchange)
layout.addWidget(self.cb)
layout.addWidget(self.lb1)
self.setLayout(layout)
def selectionchange(self, i):
self.lb1.setText(self.cb.currentText())
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MyComboBoxWindow()
win.show()
sys.exit(app.exec_())
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32