-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator.py
52 lines (47 loc) · 2.14 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
from tkinter import *
root = Tk()
root.title("Calculator")
e = Entry(root, width=37)
e.grid(row=0, column=0, columnspan=4,ipady=10)
def Input(s):
f = e.get()
e.delete(0, END)
e.insert(0, str(f)+str(s))
def Solve(s):
e.delete(0, END)
e.insert(0, eval(s))
clear = Button(root, text="C", padx=75, pady=20, command=lambda: e.delete(0, END))
divide = Button(root, text="/", padx=20, pady=20, command=lambda: Input("/"))
button7 = Button(root, text="7", padx=20, pady=20, command=lambda: Input(7))
button8 = Button(root, text="8", padx=20, pady=20, command=lambda: Input(8))
button9 = Button(root, text="9", padx=20, pady=20, command=lambda: Input(9))
multiply = Button(root, text="*", padx=20, pady=20, command=lambda: Input("*"))
button4 = Button(root, text="4", padx=20, pady=20, command=lambda: Input(4))
button5 = Button(root, text="5", padx=20, pady=20, command=lambda: Input(5))
button6 = Button(root, text="6", padx=20, pady=20, command=lambda: Input(6))
subtract = Button(root, text="-", padx=20, pady=20, command=lambda: Input("-"))
button1 = Button(root, text="1", padx=20, pady=20, command=lambda: Input(1))
button2 = Button(root, text="2", padx=20, pady=20, command=lambda: Input(2))
button3 = Button(root, text="3", padx=20, pady=20, command=lambda: Input(3))
add = Button(root, text="+", padx=20, pady=20, command=lambda: Input("+"))
decimal = Button(root, text=".", padx=20, pady=20, command=lambda: Input("."))
button0 = Button(root, text="0", padx=20, pady=20, command=lambda: Input(0))
equal = Button(root, text="=", padx=47, pady=20, command=lambda: Solve(e.get()))
clear.grid(row=1, column=0, columnspan=3)
divide.grid(row=1, column=3)
button7.grid(row=2, column=0)
button8.grid(row=2, column=1)
button9.grid(row=2, column=2)
multiply.grid(row=2, column=3)
button4.grid(row=3, column=0)
button5.grid(row=3, column=1)
button6.grid(row=3, column=2)
subtract.grid(row=3, column=3)
button1.grid(row=4, column=0)
button2.grid(row=4, column=1)
button3.grid(row=4, column=2)
add.grid(row=4, column=3)
decimal.grid(row=5, column=0)
button0.grid(row=5, column=1)
equal.grid(row=5, column=2, columnspan=4)
root.mainloop()