-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03 spin boxes.py
52 lines (34 loc) · 1.14 KB
/
03 spin boxes.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)
# Spin Box
spinB = qtw.QSpinBox( # QDoubleSpinBox for float values
value=10,
maximum=100,
minimum=0,
singleStep=10,
prefix="Value: "
# suffix="something"
)
spinB.setFont(qtg.QFont("Arial", 20))
self.layout().addWidget(spinB)
def submit():
# lab.setText(f"Value= {spinB.text()}") # with its prefix and suffix
lab.setText(f"Value= {spinB.value()}") # just the value
# Create a Button
btn = qtw.QPushButton("Submit", clicked=submit)
self.layout().addWidget(btn)
self.show()
app = qtw.QApplication([])
mw = MainWindow()
sys.exit(app.exec_())