PW Akshay

Generation

fix invalid codeSun, 11 Dec 2022

from tkinter import * def result(a,b): print(a,b) return int(a) * int(b) def btnclick(i): operation = i if(operation == "add"): res = result(e1.get(),e2.get()) e3.delete(0,END) e3.insert(0,res) elif(operation == "sub"): res = result(e1.get(),e2.get()) e3.delete(0,END) e3.insert(0,res) elif(operation == "mul"): res = result(e1.get(),e2.get()) e3.delete(0,END) e3.insert(0,res) elif(operation == "div"): res = result(e1.get(),e2.get()) e3.delete(0,END) e3.insert(0,res) else: pass def btnclear(): e1.delete(0,END) e2.delete(0,END) e3.delete(0,END) root = Tk() root.configure(bg = "white") root.title("Calculator") root.geometry("400x500") e1 = Entry(root, font = "none 30", bg = "white",width = 30) e1.pack() e2 = Entry(root, font = "none 30", bg = "white",width = 30) e2.pack() e3 = Entry(root, font = "none 30", bg = "white",width = 30) e3.pack() B_ADD = Button(root, text = "ADD", font = "none 30",width = 10, command = lambda:btnclick("add")) B_ADD.pack() B_SUB = Button(root, text = "SUB", font = "none 30",width = 10, command = lambda:btnclick("sub")) B_SUB.pack() B_MUL = Button(root, text = "MUL", font = "none 30",width = 10, command = lambda:btnclick("mul")) B_MUL.pack() B_DIV = Button(root, text = "DIV", font = "none 30",width = 10, command = lambda:btnclick("div")) B_DIV.pack() B_EQ = Button(root, text = "EQ", font = "none 30",width = 10,command = lambda:btnclick("")) B_EQ.pack() B_CLEAR = Button(root, text = "CLEAR", font = "none 30",width = 10, command = btnclear) B_CLEAR.pack() root.mainloop() if __name__ == "__main__": main()

# Exercise 3 > Practice Exe03.py and Exe04.py. # Exercise 4 > Practice Exe03.py and Exe04.py.

Questions about programming?Chat with your personal AI assistant