-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
146 lines (109 loc) · 4.37 KB
/
calculator.py
File metadata and controls
146 lines (109 loc) · 4.37 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 15 01:48:45 2022
@author: Souvik Bhattacharya
"""
from tkinter import *
root = Tk()
def click(event):
global screen_value
item = event.widget.cget("text")
if item == '=':
try:
value = eval(screen_value.get())
except Exception as e:
value = 'Error'
screen_value.set(value)
elif item == 'C':
try:
screen_value.set("")
except Exception as e:
pass
elif item == 'Del':
try:
value = screen_value.get()
value = value[:-1]
screen_value.set(value)
except Exception as e:
pass
else:
screen_value.set(screen_value.get() + item)
width = 300
height = 400
root.geometry(f'{width}x{height}')
root.minsize(width,height)
root.maxsize(width,height)
root.title('Calculator')
root.config(bg = '#343638')
screen_value = StringVar()
screen_value.set('')
screen = Entry(textvariable = screen_value,font = 'consolas 20',bg = 'lightgrey')
screen.pack(fill = 'both',padx = 5,pady = 15,ipadx = 10,ipady = 10)
f = Frame(root,bg = '#343638')
b = Button(f,text = '7',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '8',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '9',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = 'Del',padx = 20,pady = 10,bg = '#ff2d8e',font = 'consolas 15')
b.pack(side = 'left',padx = 4,pady = 1)
b.bind("<Button-1>",click)
f.pack(fill = 'both',padx = 5,pady = 1)
f = Frame(root,bg = '#343638')
b = Button(f,text = '4',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '5',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '6',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '+',padx = 20,pady = 10,bg = '#fdbc00',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
f.pack(fill = 'both',padx = 5,pady = 1)
f = Frame(root,bg = '#343638')
b = Button(f,text = '1',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '2',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '3',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '-',padx = 20,pady = 10,bg = '#fdbc00',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
f.pack(fill = 'both',padx = 5,pady = 1)
f = Frame(root,bg = '#343638')
b = Button(f,text = '0',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '%',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '/',padx = 20,pady = 10,bg = '#dffad7',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '*',padx = 20,pady = 10,bg = '#fdbc00',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
f.pack(fill = 'both',padx = 5,pady = 1)
f = Frame(root,bg = '#343638')
b = Button(f,text = 'C',padx = 20,pady = 10,bg = '#e80851',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '.',padx = 20,pady = 10,bg = '#fdbc00',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
b = Button(f,text = '=',padx = 70,pady = 10,bg = '#47e2f8',font = 'consolas 15')
b.pack(side = 'left',padx = 3,pady = 1)
b.bind("<Button-1>",click)
f.pack(fill = 'both',padx = 5,pady = 1)
root.mainloop()