-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
83 lines (55 loc) · 2.05 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
#tkinter calculator
from tkinter import*
equa = ""
root = Tk()
equation = StringVar()
calculation = Label(root, textvariable= equation )
equation.set("23+54")
calculation.grid(columnspan= 4)
def btnPress(num):
global equa
equa = equa + str(num)
equation.set(equa)
def EqualPress():
global equa
total = eval(equa)
equation.set(total)
equa =""
def Clear():
global equa
equa =""
equation.set("0")
equation.set("Enter your expression:")
Button0 = Button(root, text= "0",command= lambda: btnPress(0))
Button0.grid(row= 4, column= 1)
Button1 = Button(root, text= "1",command= lambda: btnPress(1))
Button1.grid(row= 1, column= 0)
Button2 = Button(root, text= "2",command= lambda: btnPress(2))
Button2.grid(row= 1, column= 1)
Button3 = Button(root, text= "3",command= lambda: btnPress(3))
Button3.grid(row= 1, column= 2)
Button4 = Button(root, text= "4",command= lambda: btnPress(4))
Button4.grid(row= 2, column= 0)
Button5 = Button(root, text= "5",command= lambda: btnPress(5))
Button5.grid(row= 2, column= 1)
Button6 = Button(root, text= "6",command= lambda: btnPress(6))
Button6.grid(row= 2, column= 2)
Button7 = Button(root, text= "7",command= lambda: btnPress(7))
Button7.grid(row= 3, column= 0)
Button8 = Button(root, text= "8",command= lambda: btnPress(8))
Button8.grid(row= 3, column= 1)
Button9 = Button(root, text= "9",command= lambda: btnPress(9))
Button9.grid(row= 3, column= 2)
Plus = Button(root, text= "+",command= lambda: btnPress("+"))
Plus.grid(row= 1, column=3 )
Minus = Button(root, text= "-",command= lambda: btnPress("-"))
Minus.grid(row= 2, column= 3)
Multiply = Button(root, text= "*",command= lambda: btnPress("*"))
Multiply.grid(row= 3, column= 3)
Divide = Button(root, text= "/",command= lambda: btnPress("/"))
Divide.grid(row= 4, column=3 )
Equals = Button(root, text= "=", command= EqualPress)
Equals.grid(row= 4, column= 2)
Clear = Button(root, text= "C",command = Clear)
Clear.grid(row= 4, column= 0)
root.mainloop()