This repository was archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCalculator.py
More file actions
68 lines (68 loc) · 2.63 KB
/
Copy pathCalculator.py
File metadata and controls
68 lines (68 loc) · 2.63 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
from tkinter import *
from tkinter import messagebox
class Calculator():
def __init__(self):
self.window=Tk()
self.window.title("Calculator")
self.NF=Frame(self.window)
self.NF.grid(row=0,column=0,columnspan=5,padx=3,pady=3)
self.L1=Label(self.NF,text="1st Number :")
self.L1.grid(row=0,column=1,sticky=E)
self.L2=Label(self.NF,text="2nd Number :")
self.L2.grid(row=1,column=1,sticky=E)
self.L3=Label(self.NF,text="Answer :")
self.L3.grid(row=2,column=1,sticky=E)
self.E1=Entry(self.NF)
self.E1.grid(row=0,column=2)
self.E2=Entry(self.NF)
self.E2.grid(row=1,column=2)
self.E3=Entry(self.NF)
self.E3.grid(row=2,column=2)
self.BF=Frame(self.window)
self.BF.grid(row=4,column=0,columnspan=5,padx=3,pady=3)
self.B1=Button(self.BF,text="ADD",pady=2,padx=5,bg="lightblue",command=self.addition)
self.B1.grid(row=0,column=0,pady=2,padx=5)
self.B2=Button(self.BF,text="SUB",pady=2,padx=5,bg="lightblue",command=self.subtraction)
self.B2.grid(row=0,column=1,pady=2,padx=5)
self.B3=Button(self.BF,text="MUL",pady=2,padx=5,bg="lightblue",command=self.multiplication)
self.B3.grid(row=0,column=2,pady=2,padx=5)
self.B4=Button(self.BF,text="DIV",pady=2,padx=5,bg="lightblue",command=self.division)
self.B4.grid(row=0,column=3,pady=2,padx=5)
self.B5=Button(self.BF,text="CLR",pady=2,padx=5,bg="lightblue",command=self.clear)
self.B5.grid(row=0,column=4,pady=2,padx=5)
self.window.mainloop()
def addition(self):
if(self.E1.get()=="" or self.E2.get==""):
messagebox.showinfo('Warning!','Enter Valid Input')
return
r=round(float(self.E1.get())+float(self.E2.get()),2)
self.E3.delete(0,len(self.E3.get())-1)
self.E3.insert(0,str(r))
def subtraction(self):
if(self.E1.get()=="" or self.E2.get==""):
messagebox.showinfo('Warning!','Enter Valid Input')
return
r=round(float(self.E1.get())-float(self.E2.get()),2)
self.E3.delete(0,len(self.E3.get())-1)
self.E3.insert(0,str(r))
def multiplication(self):
if(self.E1.get()=="" or self.E2.get==""):
messagebox.showinfo('Warning!','Enter Valid Input')
return
r=round(float(self.E1.get())*float(self.E2.get()),2)
self.E3.delete(0,len(self.E3.get())-1)
self.E3.insert(0,str(r))
def division(self):
if(self.E1.get()=="" or self.E2.get==""):
messagebox.showinfo('Warning!','Enter Valid Input')
return
r=round(float(self.E1.get())/float(self.E2.get()),2)
self.E3.delete(0,len(self.E3.get())-1)
self.E3.insert(0,str(r))
def clear(self):
if messagebox.askquestion('Clear','Are you sure?'):
self.E1.delete(0,len(self.E1.get()))
self.E2.delete(0,len(self.E2.get()))
self.E3.delete(0,len(self.E3.get()))
if __name__=="__main__":
Calculator()