-
Notifications
You must be signed in to change notification settings - Fork 0
/
arithmatic.py
60 lines (59 loc) · 2.07 KB
/
arithmatic.py
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
from tkinter import *
class MyWindow:
def __init__(self, win):
self.lbl1=Label(win, text='First number')
self.lbl2=Label(win, text='Second number')
self.lbl3=Label(win, text='Result')
self.t1=Entry(bd=3)
self.t2=Entry()
self.t3=Entry()
self.btn1 = Button(win, text='Add')
self.btn2=Button(win, text='Subtract')
self.btn3=Button(win,text="Multilication")
self.btn4=Button(win,text="Division")
self.lbl1.place(x=100, y=50)
self.t1.place(x=200, y=50)
self.lbl2.place(x=100, y=100)
self.t2.place(x=200, y=100)
self.b1=Button(win, text='Add', command=self.add)
self.b2=Button(win, text='Subtract')
self.b2.bind('<Button-1>', self.sub)
self.b3=Button(win,text="Multiplication")
self.b3.bind('<Button-1>',self.mul)
self.b4=Button(win,text="Divisin")
self.b4.bind('<Button-1>',self.div)
self.b1.place(x=100, y=150)
self.b2.place(x=200, y=150)
self.b3.place(x=300,y=150)
self.b4.place(x=400,y=150)
self.lbl3.place(x=100, y=200)
self.t3.place(x=200, y=200)
def add(self):
self.t3.delete(0, 'end')
num1=int(self.t1.get())
num2=int(self.t2.get())
result=num1+num2
self.t3.insert(END, str(result))
def sub(self, event):
self.t3.delete(0, 'end')
num1=int(self.t1.get())
num2=int(self.t2.get())
result=num1-num2
self.t3.insert(END, str(result))
def mul(self, event):
self.t3.delete(0, 'end')
num1=int(self.t1.get())
num2=int(self.t2.get())
result=num1*num2
self.t3.insert(END, str(result))
def div(self, event):
self.t3.delete(0, 'end')
num1=int(self.t1.get())
num2=int(self.t2.get())
result=num1/num2
self.t3.insert(END, str(result))
window=Tk()
mywin=MyWindow(window)
window.title('Tkinter Arthematic operations')
window.geometry("700x500+10+10")
window.mainloop()