forked from TabishAjaz/hackoctober
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_Calculator.py
More file actions
122 lines (90 loc) · 4 KB
/
GUI_Calculator.py
File metadata and controls
122 lines (90 loc) · 4 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
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
121
122
from tkinter import *
cal = Tk()
cal.geometry("410x460")
cal.title("CALCULATOR")
cal.title("CALCULATOR")
callabel = Label(cal, text="CALCULATOR", bg='white', font=("Times", 20, 'bold'))
callabel.pack(side=TOP)
cal.config(background='light blue')
textin = StringVar()
operator = ""
def clickbut(number):
global operator
operator = operator + str(number)
textin.set(operator)
def equlbut():
global operator
addition = str(eval(operator))
textin.set(addition)
operator = ''
def equlbut():
global operator
substraction = str(eval(operator))
textin.set(substraction)
operator = ''
def equlbut():
global operator
multiplication = str(eval(operator))
textin.set(multiplication)
operator = ''
def equlbut():
global operator
division = str(eval(operator))
textin.set(division)
operator = ''
def clrbut():
textin.set('')
caltext = Entry(cal, font=("Calibri (Body)", 12, 'bold'), textvar=textin, width=25, bd=5, bg='light gray')
caltext.pack()
but1 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(1), text="1",
font=("Calibri (Body)", 16, 'bold'))
but1.place(x=10, y=100)
but2 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(2), text="2",
font=("Calibri (Body)", 16, 'bold'))
but2.place(x=10, y=170)
but3 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(3), text="3",
font=("Calibri (Body)", 16, 'bold'))
but3.place(x=10, y=240)
but4 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(4), text="4",
font=("Calibri (Body)", 16, 'bold'))
but4.place(x=75, y=100)
but5 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(5), text="5",
font=("Calibri (Body)", 16, 'bold'))
but5.place(x=75, y=170)
but6 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(6), text="6",
font=("Calibri (Body)", 16, 'bold'))
but6.place(x=75, y=240)
but7 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(7), text="7",
font=("Calibri (Body)", 16, 'bold'))
but7.place(x=140, y=100)
but8 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(8), text="8",
font=("Calibri (Body)", 16, 'bold'))
but8.place(x=140, y=170)
but9 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(9), text="9",
font=("Calibri (Body)", 16, 'bold'))
but9.place(x=140, y=240)
but0 = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', command=lambda: clickbut(0), text="0",
font=("Calibri (Body)", 16, 'bold'))
but0.place(x=10, y=310)
butdot = Button(cal, padx=47, pady=14, bd=4, bg='light yellow', command=lambda: clickbut("."), text=".",
font=("Calibri (Body)", 16, 'bold'))
butdot.place(x=75, y=310)
butpl = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', text="+", command=lambda: clickbut("+"),
font=("Calibri (Body)", 16, 'bold'))
butpl.place(x=205, y=100)
butsub = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', text="-", command=lambda: clickbut("-"),
font=("Calibri (Body)", 16, 'bold'))
butsub.place(x=205, y=170)
butml = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', text="*", command=lambda: clickbut("*"),
font=("Calibri (Body)", 16, 'bold'))
butml.place(x=205, y=240)
butdiv = Button(cal, padx=14, pady=14, bd=4, bg='light yellow', text="/", command=lambda: clickbut("/"),
font=("Calibri (Body)", 16, 'bold'))
butdiv.place(x=205, y=310)
butclear = Button(cal, padx=14, pady=119, bd=4, bg='light yellow', text="CE", command=clrbut,
font=("Calibri (Body)", 16, 'bold'))
butclear.place(x=270, y=100)
butequal = Button(cal, padx=151, pady=14, bd=4, bg='light yellow', command=equlbut, text="=",
font=("Calibri (Body)", 16, 'bold'))
butequal.place(x=10, y=380)
cal.mainloop()