-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calculator_GUI
98 lines (65 loc) · 1.71 KB
/
Calculator_GUI
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
from tkinter import*
root = Tk()
root.geometry("300x350")
root.title("Calculator")
Alan = Entry(font="Verdana 14 bold", width=18, justify=RIGHT)
Alan.place(x=20, y=20)
def write(x):
w = len(Alan.get())
Alan.insert(w,str(x))
#print(x)
n1 = 0
hesap = 5
def operation(x):
global n1
n1 = float(Alan.get())
global hesap
hesap = x
print(n1)
print(hesap)
Alan.delete(0,END)
n2 = 0
def calculate():
global n2
n2 = float(Alan.get())
print(n2)
global hesap
result = 0
if hesap==0:
result = n1 + n2
elif hesap==1:
result = n1 - n2
elif hesap==2:
result = n1 * n2
elif hesap==3:
result = n1 / n2
Alan.delete(0,END)
Alan.insert(0,str(result))
def clear():
Alan.delete(0,END)
number = []
for i in range(1,10):
number.append(Button(text=str(i),font="Verdana 14 bold", command=lambda x=i:write(x)))
sayi = 0
for i in range(0,3):
for j in range(0,3):
number[sayi].place(x=55+50*j, y=70+50*i)
sayi += 1
islem = []
for i in range(0,4):
islem.append(Button(font="Verdana 14 bold", width=2, command=lambda x=i:operation(x)))
for i in range(0,4):
islem[i].place(x=205, y=70+50*i)
islem[0]["text"] = "+"
islem[1]["text"] = "-"
islem[2]["text"] = "*"
islem[3]["text"] = "/"
nb = Button(text=".", font="Verdana 14 bold", width=2, command=lambda x=".":write(x))
nb.place(x=55, y=220)
sb = Button(text="0", font="Verdana 14 bold", command=lambda x=0:write(x))
sb.place(x=105, y=220)
eb = Button(text="=", font="Verdana 14 bold",fg="grey", command=calculate)
eb.place(x=155, y=220)
cb = Button(text="c", font="Verdana 14 bold", width=10, command=clear)
cb.place(x=75, y=270)
root.mainloop()