Hi,
i have just started programming with python and i have beken given a task where i must create a python calculator.
So far i have created the code (seen below) however i need help explaining it-e.g. saying what each part of the code does:
from tkinter import *
root = Tk()
root.title("Python Calculator")
button_layout_Design = [
"1","2","3","+",
"4","5","6","-",
"7","8","9","*",
"C","0","=","/"
]
r = 1
c = 0
for buttons in button_layout_Design:
cmd = lambda key=buttons: onClick(key)
Button(root,text=buttons,relief="flat",command=cmd).grid(row=r,column=c)
c += 1
if c > 3:
r += 1
c = 0
view = Entry(root)
view.grid(row=0,column=0,columnspan=4)
def onClick(key):
if key == "C":
view.delete(0,END)
elif key == "=":
try:
ans = eval(view.get())
view.delete(0,END)
view.insert(0,ans)
except SyntaxError:
view.delete(0,END)
view.insert(0,"Syntax Error")
except ZeroDivisionError:
view.delete(0,END)
view.insert(0,"You cann't divide by zero!")
else:
view.insert(END,key)
Any help would be much appreciated!