-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode
120 lines (87 loc) · 3.09 KB
/
code
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
from tkinter import *
root = Tk()
root.title("Calculator")
display = Entry(0, width=30, border=5,)
display.grid(row=0, column=0, columnspan=4)
def number(num):
c = display.get()
display.delete(0, END)
display.insert(0, str(c) + str(num))
def clear():
display.delete(0, END)
def p():
f = display.get()
global cu
cu = f
int(cu)
display.delete(0, END)
global s
s = "p"
def m():
global cu
cu = display.get()
display.delete(0, END)
global s
s = "m"
def mu():
global cu
cu = display.get()
display.delete(0, END)
global s
s = "mu"
def d():
global cu
cu = display.get()
display.delete(0, END)
global s
s = "d"
def eq():
a = int(cu)
b = display.get()
b1 = int(b)
display.delete(0, END)
if s == "p":
ans = (a + b1)
display.insert(0, ans)
if s == "m":
ans = (a - b1)
display.insert(0, ans)
if s == "mu":
ans = (a * b1)
display.insert(0, ans)
if s == "d":
ans = (a / b1)
display.insert(0, ans)
button_1 = Button(text="1", padx=17, pady=12, command=lambda: number(1), fg="white", bg="#fc5e03")
button_2 = Button(text="2", padx=17, pady=12, command=lambda: number(2), fg="white", bg="#fc5e03")
button_3 = Button(text="3", padx=17, pady=12, command=lambda: number(3), fg="white", bg="#fc5e03")
button_4 = Button(text="4", padx=17, pady=12, command=lambda: number(4), fg="white", bg="#fc5e03")
button_5 = Button(text="5", padx=17, pady=12, command=lambda: number(5), fg="white", bg="#fc5e03")
button_6 = Button(text="6", padx=17, pady=12, command=lambda: number(6), fg="white", bg="#fc5e03")
button_7 = Button(text="7", padx=17, pady=12, command=lambda: number(7), fg="white", bg="#fc5e03")
button_8 = Button(text="8", padx=17, pady=12, command=lambda: number(8), fg="white", bg="#fc5e03")
button_9 = Button(text="9", padx=17, pady=12, command=lambda: number(9), fg="white", bg="#fc5e03")
button_0 = Button(text="0", padx=17, pady=12, command=lambda: number(0), fg="white", bg="#fc5e03")
button_plus = Button(text="+", padx=15, pady=12, command=p, fg="white", bg="#fc5e03")
button_minus = Button(text="-", padx=17, pady=12, command=m, fg="white", bg="#fc5e03")
button_multi = Button(text="*", padx=17, pady=12, fg="white", command=mu, bg="#fc5e03")
button_divide = Button(text="/", padx=17, pady=12, command=d, fg="white", bg="#fc5e03")
button_Equal = Button(text="=", padx=17, pady=12, command=eq, fg="Black", bg="white")
button_clear = Button(text="C", padx=16, pady=12, command=clear, fg="black", bg="white")
button_9.grid(row=2, column=2)
button_8.grid(row=2, column=1)
button_7.grid(row=2, column=0)
button_6.grid(row=3, column=2)
button_5.grid(row=3, column=1)
button_4.grid(row=3, column=0)
button_3.grid(row=4, column=2)
button_2.grid(row=4, column=1)
button_1.grid(row=4, column=0)
button_0.grid(row=5, column=1)
button_plus.grid(row=4, column=3)
button_minus.grid(row=3, column=3)
button_multi.grid(row=2, column=3)
button_divide.grid(row=1, column=3)
button_Equal.grid(row=5, column=3)
button_clear.grid(row=1, column=2)
root.mainloop()