|
| 1 | +from tkinter import * |
| 2 | +class MyWindow: |
| 3 | + def __init__(self, win): |
| 4 | + self.lbl1=Label(win, text='First number') |
| 5 | + self.lbl2=Label(win, text='Second number') |
| 6 | + self.lbl3=Label(win, text='Result') |
| 7 | + self.t1=Entry(bd=3) |
| 8 | + self.t2=Entry() |
| 9 | + self.t3=Entry() |
| 10 | + self.btn1 = Button(win, text='Add') |
| 11 | + self.btn2=Button(win, text='Subtract') |
| 12 | + self.btn3=Button(win,text="Multilication") |
| 13 | + self.btn4=Button(win,text="Division") |
| 14 | + self.lbl1.place(x=100, y=50) |
| 15 | + self.t1.place(x=200, y=50) |
| 16 | + self.lbl2.place(x=100, y=100) |
| 17 | + self.t2.place(x=200, y=100) |
| 18 | + self.b1=Button(win, text='Add', command=self.add) |
| 19 | + self.b2=Button(win, text='Subtract') |
| 20 | + self.b2.bind('<Button-1>', self.sub) |
| 21 | + self.b3=Button(win,text="Multiplication") |
| 22 | + self.b3.bind('<Button-1>',self.mul) |
| 23 | + self.b4=Button(win,text="Divisin") |
| 24 | + self.b4.bind('<Button-1>',self.div) |
| 25 | + self.b1.place(x=100, y=150) |
| 26 | + self.b2.place(x=200, y=150) |
| 27 | + self.b3.place(x=300,y=150) |
| 28 | + self.b4.place(x=400,y=150) |
| 29 | + self.lbl3.place(x=100, y=200) |
| 30 | + self.t3.place(x=200, y=200) |
| 31 | + def add(self): |
| 32 | + self.t3.delete(0, 'end') |
| 33 | + num1=int(self.t1.get()) |
| 34 | + num2=int(self.t2.get()) |
| 35 | + result=num1+num2 |
| 36 | + self.t3.insert(END, str(result)) |
| 37 | + def sub(self, event): |
| 38 | + self.t3.delete(0, 'end') |
| 39 | + num1=int(self.t1.get()) |
| 40 | + num2=int(self.t2.get()) |
| 41 | + result=num1-num2 |
| 42 | + self.t3.insert(END, str(result)) |
| 43 | + def mul(self, event): |
| 44 | + self.t3.delete(0, 'end') |
| 45 | + num1=int(self.t1.get()) |
| 46 | + num2=int(self.t2.get()) |
| 47 | + result=num1*num2 |
| 48 | + self.t3.insert(END, str(result)) |
| 49 | + def div(self, event): |
| 50 | + self.t3.delete(0, 'end') |
| 51 | + num1=int(self.t1.get()) |
| 52 | + num2=int(self.t2.get()) |
| 53 | + result=num1/num2 |
| 54 | + self.t3.insert(END, str(result)) |
| 55 | + |
| 56 | +window=Tk() |
| 57 | +mywin=MyWindow(window) |
| 58 | +window.title('Tkinter Arthematic operations') |
| 59 | +window.geometry("700x500+10+10") |
| 60 | +window.mainloop() |
0 commit comments