-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
60 lines (53 loc) · 2.48 KB
/
Calculator.py
File metadata and controls
60 lines (53 loc) · 2.48 KB
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
from tkinter import *
wind = Tk()
wind.title("Calculator")
wind.geometry("390x380+400+100")
wind.resizable(0, 0)
wind.config(bg="#9fa8da")
class Calc:
def __init__(self, index, xx, yy):
t = textButList[index]
if t == "=":
button = Button(wind, width=w, height=h, command=lambda: self.btn(t), bg=colors[index], text=t,
activebackground="#ec407a", relief="groove", bd=4, cursor="hand2", font="1" ).place(x=xx, y=yy)
elif t == "C":
button = Button(wind, width=w, height=h, command=lambda: self.btn(t), bg=colors[index], text=t,
activebackground="#ec407a", relief="groove", bd=4, cursor="hand2", font="1").place(x=xx, y=yy)
elif t == "del":
button = Button(wind, width=w, height=h, command=lambda: self.btn(t), bg=colors[index], text=t,
activebackground="#ec407a", relief="groove", bd=4, cursor="hand2", font="1").place(x=xx, y=yy)
else:
button = Button(wind, width=w, height=h, command=lambda: self.btn(t), bg=colors[index], text=t,
activebackground="#ec407a", relief="groove", bd=4, cursor="hand2", font="1").place(x=xx, y=yy)
def btn(self, tool):
global globtxt
if tool == "=":
try:
globtxt = str(eval(globtxt))
except:
globtxt = "--- Invalid Input ---"
string.set(globtxt)
globtxt = ""
elif tool == "C":
string.set("")
globtxt = ""
elif tool == "del":
globtxt = globtxt[:-1]
string.set(globtxt)
else:
globtxt = globtxt + str(tool)
string.set(globtxt)
globtxt, string, w, h, xPos, yPos, myIndex = "", StringVar(), 6, 3, 10, 75, 0
field = Label(wind, width=38, height=2, textvariable=string, bg="#fce4ec", font="1").place(x=20, y=15)
textButList, colors = ["1","4","7","(","2","5","8","0","3","6","9",")","+","-","*","/","C","=","del","."],\
["#e0f7fa","#e0f7fa","#e0f7fa","#81d4fa","#e0f7fa","#e0f7fa","#e0f7fa","#e0f7fa",
"#e0f7fa","#e0f7fa","#e0f7fa","#81d4fa","#81d4fa","#81d4fa","#81d4fa","#81d4fa",
"#4db6ac","#4db6ac","#4db6ac","#81d4fa"]
for x in range(5):
for y in range(4):
mine = Calc(myIndex, xPos, yPos)
yPos += 75
myIndex += 1
yPos = 75
xPos += 75
wind.mainloop()