FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python/calculator.py at main · Brian342/python · GitHub
Brian342
/
python
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python
/
calculator.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
122 lines (82 loc) · 3.18 KB
Breadcrumbs
python
/
calculator.py
Copy path
File metadata and controls
122 lines (82 loc) · 3.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from
tkinter
import
*
def
button_press
(
num
):
global
equation_text
equation_text
=
equation_text
+
str
(
num
)
equation_label
.
set
(
equation_text
)
def
equals
():
global
equation_text
try
:
total
=
str
(
eval
(
equation_text
))
equation_label
.
set
(
total
)
equation_text
=
total
except
SyntaxError
:
equation_label
.
set
(
"Syntax error"
)
equation_text
=
""
except
ZeroDivisionError
:
equation_label
.
set
(
"arithmetic error"
)
equation_text
=
""
def
clear
():
global
equation_text
equation_label
.
set
(
""
)
equation_text
=
""
window
=
Tk
()
window
.
title
(
"Calculator program"
)
window
.
geometry
(
"500x500"
)
equation_text
=
""
equation_label
=
StringVar
()
label
=
Label
(
window
,
textvariable
=
equation_label
,
font
=
(
'consolas'
,
20
),
bg
=
'black'
,
width
=
24
,
height
=
2
)
label
.
pack
()
frame
=
Frame
(
window
)
frame
.
pack
()
button1
=
Button
(
frame
,
text
=
1
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
1
))
button1
.
grid
(
row
=
0
,
column
=
0
)
button2
=
Button
(
frame
,
text
=
2
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
2
))
button2
.
grid
(
row
=
0
,
column
=
1
)
button3
=
Button
(
frame
,
text
=
3
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
3
))
button3
.
grid
(
row
=
0
,
column
=
2
)
button4
=
Button
(
frame
,
text
=
4
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
4
))
button4
.
grid
(
row
=
1
,
column
=
0
)
button5
=
Button
(
frame
,
text
=
5
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
5
))
button5
.
grid
(
row
=
1
,
column
=
1
)
button6
=
Button
(
frame
,
text
=
6
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
6
))
button6
.
grid
(
row
=
1
,
column
=
2
)
button7
=
Button
(
frame
,
text
=
7
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
7
))
button7
.
grid
(
row
=
2
,
column
=
0
)
button8
=
Button
(
frame
,
text
=
8
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
8
))
button8
.
grid
(
row
=
2
,
column
=
1
)
button9
=
Button
(
frame
,
text
=
9
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
9
))
button9
.
grid
(
row
=
2
,
column
=
2
)
button0
=
Button
(
frame
,
text
=
0
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
0
))
button0
.
grid
(
row
=
3
,
column
=
1
)
plus
=
Button
(
frame
,
text
=
'+'
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
'+'
))
plus
.
grid
(
row
=
0
,
column
=
3
)
minus
=
Button
(
frame
,
text
=
'-'
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
'-'
))
minus
.
grid
(
row
=
1
,
column
=
3
)
multiply
=
Button
(
frame
,
text
=
'*'
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
'*'
))
multiply
.
grid
(
row
=
2
,
column
=
3
)
divide
=
Button
(
frame
,
text
=
'/'
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
'/'
))
divide
.
grid
(
row
=
3
,
column
=
3
)
equal
=
Button
(
frame
,
text
=
'='
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
equals
)
equal
.
grid
(
row
=
3
,
column
=
2
)
decimal
=
Button
(
frame
,
text
=
'.'
,
height
=
4
,
width
=
9
,
font
=
35
,
command
=
lambda
:
button_press
(
'.'
))
decimal
.
grid
(
row
=
3
,
column
=
0
)
clear
=
Button
(
window
,
text
=
'clear'
,
height
=
4
,
width
=
20
,
font
=
35
,
command
=
clear
)
clear
.
pack
()
window
.
mainloop
()
Back
|
FazBrowse Home
|
New Git URL