-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
161 lines (120 loc) · 5.16 KB
/
calculator.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import tkinter as tk
HEIGHT=1000
WIDTH=1000
expression = ""
def button_plus_clicked():
global expression
expression = expression + "+"
print(expression)
text_box.insert(tk.INSERT, "+")
def button_minus_clicked():
global expression
expression = expression + "-"
print(expression)
text_box.insert(tk.INSERT , "-")
def button_multi_clicked():
global expression
expression = expression + "*"
print(expression)
text_box.insert(tk.INSERT , "*")
def button_divide_clicked():
global expression
expression = expression + "/"
print(expression)
text_box.insert(tk.INSERT , "/")
def button_1_clicked():
global expression
expression = expression + "1"
print(expression)
text_box.insert(tk.INSERT , "1")
def button_2_clicked():
global expression
expression = expression + "2"
print(expression)
text_box.insert(tk.INSERT , "2")
def button_3_clicked():
global expression
expression = expression + "3"
text_box.insert(tk.INSERT , "3")
def button_4_clicked():
global expression
expression = expression + "4"
print(expression)
text_box.insert(tk.INSERT , "4")
def button_5_clicked():
global expression
expression = expression + "5"
print(expression)
text_box.insert(tk.INSERT , "5")
def button_6_clicked():
global expression
expression = expression + "6"
print(expression)
text_box.insert(tk.INSERT , "6")
def button_7_clicked():
global expression
expression= expression + "7"
print(expression)
text_box.insert(tk.INSERT , "7")
def button_8_clicked():
global expression
expression= expression + "8"
print(expression)
text_box.insert(tk.INSERT , "8")
def button_9_clicked():
global expression
expression= expression + "9"
print(expression)
text_box.insert(tk.INSERT , "9")
def button_0_clicked():
global expression
expression= expression + "0"
print(expression)
text_box.insert(tk.INSERT , "0")
def cleared():
text_box.delete('1.0' , tk.END)
global expression
expression = ""
def equate():
text_box.insert(tk.INSERT , "\n" + "= " + str(eval(expression)))
root = tk.Tk()
root.title('Calculator')
text_box = tk.Text(root, font=10)
text_box.pack()
canvas = tk.Canvas(root , height=HEIGHT , width=WIDTH , bg="cyan")
canvas.pack()
frame = tk.Frame(root , bg="medium spring green", bd=10)
frame.place(relx=0 , rely=0.4 , relwidth=1 , relheight=0.6)
button=tk.Button(frame , text="+" , font=1000000000, bg="cyan" , command=button_plus_clicked)
button.place(relx=0, rely=0, relwidth=0.2 , relheight=0.3)
button_2 = tk.Button(frame , text="-" , font=100000000 , bg="cyan", command=button_minus_clicked)
button_2.place(relx=0 , rely=0.25 , relwidth=0.2 , relheight=0.3)
button_3 = tk.Button(frame , text="*" , font=100000000 ,bg="cyan" , command=button_multi_clicked)
button_3.place(relx=0 , rely=0.5 , relwidth=0.2 , relheight=0.3)
button_100 = tk.Button(frame , text="/" , font=1000000000 ,bg="cyan" , command=button_divide_clicked)
button_100.place(relx=0 , rely=0.75 , relwidth=0.2 , relheight=0.3)
button_4 = tk.Button(frame , text="1" , font=10000 ,bg="peachpuff" , command=button_1_clicked)
button_4.place(relx=0.3 , rely=0 , relwidth=0.15 , relheight=0.3)
button_5 = tk.Button(frame , text="2" , font=10000 ,bg="peachpuff" , command=button_2_clicked)
button_5.place(relx=0.45 , rely=0 , relwidth=0.15 , relheight=0.3)
button_6 = tk.Button(frame , text="3" , font=10000 ,bg="peachpuff" , command=button_3_clicked)
button_6.place(relx=0.6 , rely=0 , relwidth=0.15 , relheight=0.3)
button_7 = tk.Button(frame , text="4" , font=10000 ,bg="peachpuff" , command=button_4_clicked)
button_7.place(relx=0.3 , rely=0.3 , relwidth=0.15 , relheight=0.3)
button_8 = tk.Button(frame , text="5" , font=10000 ,bg="peachpuff" , command=button_5_clicked)
button_8.place(relx=0.45 , rely=0.3 , relwidth=0.15 , relheight=0.3)
button_9 = tk.Button(frame , text="6" , font=10000 ,bg='peachpuff' , command=button_6_clicked)
button_9.place(relx=0.6 , rely=0.3 , relwidth=0.15 , relheight=0.3)
button_10 = tk.Button(frame , text="7" , font=10000 ,bg="peachpuff" , command=button_7_clicked)
button_10.place(relx=0.3 , rely=0.6 , relwidth=0.15 , relheight=0.3)
button_11 = tk.Button(frame , text="8" , font=10000 ,bg="peachpuff", command=button_8_clicked)
button_11.place(relx=0.45 , rely=0.6 , relwidth=0.15 , relheight=0.3)
button_12 = tk.Button(frame , text="9" , font=10000 ,bg="peachpuff" , command=button_9_clicked)
button_12.place(relx=0.6 , rely=0.6 , relwidth=0.15 , relheight=0.3)
button_13 = tk.Button(frame , text="0" , font=10000 ,bg="slateblue1" , command=button_0_clicked)
button_13.place(relx=0.8 , rely=0 , relwidth=0.15 , relheight = 0.3)
button_14 = tk.Button(frame , text="C" , font=10000 ,bg="slateblue1", command=cleared)
button_14.place(relx=0.8 , rely=0.3 , relwidth=0.15 , relheight = 0.3)
button_15 = tk.Button(frame , text="=" , font=10000 ,bg="slateblue1", command=equate)
button_15.place(relx=0.8 , rely=0.6 , relwidth=0.15 , relheight = 0.3)
root.mainloop()