-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.kv
85 lines (74 loc) · 1.87 KB
/
calculator.kv
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#:import NumBases components.enums.NumBases
# Define Widgets
<CalcInput>
multiline: False
# When submitted
on_text_validate: self.eval()
<CalcButton@Button>:
# Default button from which
# all buttons will be derived
<OpButton>
<NumButton@CalcButton>
# UIX
BoxLayout:
orientation: "vertical"
padding: 20
CalcInput:
id: num_input
text: "0"
on_focus: pass
size_hint_y: None
height: 100
GridLayout:
rows: 5
cols: 3
# Row 5
OpButton:
text: "Dec"
on_press: num_input.prev_base = num_input.base; num_input.base = NumBases.DEC; num_input.eval()
OpButton:
text: "Bin"
on_press: num_input.prev_base = num_input.base; num_input.base = NumBases.BIN; num_input.eval()
OpButton:
text: "Hex"
on_press: num_input.prev_base = num_input.base; num_input.base = NumBases.HEX; num_input.eval()
# Row 4
OpButton:
text: "+"
on_press: num_input.add_input(f" {self.text} ")
OpButton:
text: "-"
on_press: num_input.add_input(f" {self.text} ")
OpButton:
text: "="
on_press: num_input.eval()
# Row 3
NumButton:
text: "7"
on_press: num_input.add_input(self.text)
NumButton:
text: "8"
on_press: num_input.add_input(self.text)
NumButton:
text: "9"
on_press: num_input.add_input(self.text)
# Row 2
Button:
text: "4"
on_press: num_input.add_input(self.text)
Button:
text: "5"
on_press: num_input.add_input(self.text)
Button:
text: "6"
on_press: num_input.add_input(self.text)
# Row 1
Button:
text: "1"
on_press: num_input.add_input(self.text)
Button:
text: "2"
on_press: num_input.add_input(self.text)
Button:
text: "3"
on_press: num_input.add_input(self.text)