In: Computer Science
1. Please use Python 3 programing.
2. Please share your code.
3. Please show all outputs.
Create a GUI Calculator with the following:
Title : Calculator
Label and Entry box for 1st Number
Label and Entry box for 2nd Number
Buttons for *, /, +, -
Label for result and Displaying the result
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.Calculator1=Entry(bd=3)
self.t2=Entry()
self.t3=Entry()
self.btn1 = Button(win, text='Add')
self.btn2=Button(win, text='Subtract')
self.lbl1.place(x=100, y=50)
self.Calculator1.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='Multiply')
self.b3.bind('<Button-1>', self.mul)
self.b4=Button(win, text='Devide')
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.Calculator1.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.Calculator1.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.Calculator1.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.Calculator1.get())
num2=int(self.t2.get())
result=num1/num2
self.t3.insert(END, str(result))
window=Tk()
mywin=MyWindow(window)
window.title('Hello Python')
window.geometry("500x300+10+10")
window.mainloop()