-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02 combo box.py
52 lines (35 loc) · 1.34 KB
/
02 combo box.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import PyQt5.QtWidgets as qtw
import PyQt5.QtGui as qtg
class MainWindow(qtw.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle("Hello World!")
# Set Vertical Layout
self.setLayout(qtw.QVBoxLayout())
# Label
lab = qtw.QLabel("Whats Your Name?")
lab.setFont(qtg.QFont("Arial", 20))
self.layout().addWidget(lab)
# Combo Box
combo = qtw.QComboBox(
editable=True, # defines new elements for user
insertPolicy=qtw.QComboBox.InsertAtTop # defines position for new elements
)
# Adding Items
combo.addItem("Pep", "Pep's Data")
combo.addItems(["Cheese", "Mushrooms"])
combo.insertItem(1, "Inserted") # insert item on a specific idx
# combo.insertItems(0, ["items"]) # insert items on a specific idx
self.layout().addWidget(combo)
def submit():
lab.setText(f"You Picked: {combo.currentText()}!")
# lab.setText(f"You Picked: {combo.currentData()}!")
# lab.setText(f"You Picked: {combo.currentIndex()}!")
# Create a Button
btn = qtw.QPushButton("Submit", clicked=submit)
self.layout().addWidget(btn)
self.show()
app = qtw.QApplication([])
mw = MainWindow()
sys.exit(app.exec_())