from tkinter import *


def click(event):
    global scvalue
    text = event.widget.cget("text")        # by this function you can get text of that button
    # print(text)
    if text == "=":
        if scvalue.get().isdigit():
            value = int(scvalue.get())
        else:
            try:
                value = eval(screen.get())
            except Exception as e:
                print(e)
                value = "Error"

        scvalue.set(value)
        screen.update()
    elif text == "C":
        scvalue.set("")
        screen.update()
    else:
        scvalue.set(scvalue.get() + text)
        screen.update()


root = Tk()
root.geometry("600x850")
# root.minsize(400, 600)
# root.maxsize(400, 600)
root.title("Calculator By Devendra")

scvalue = StringVar()
scvalue.set("")
screen = Entry(root, textvar=scvalue, font="lucida 40 bold")
screen.pack(fill=X, ipadx=80, pady=15, padx=10)

f = Frame(root, bg="grey")
b = Button(f, text="9", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="8", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="7", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="C", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=10)
b.bind("<Button-1>", click)
f.pack()

# ----------------------------------------------------------------------------------------------------------

f = Frame(root, bg="grey")
b = Button(f, text="6", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="5", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="4", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="+", padx=9, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
f.pack()

# ----------------------------------------------------------------------------------------------------------

f = Frame(root, bg="grey")
b = Button(f, text="3", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="2", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="1", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="-", padx=19, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=10)
b.bind("<Button-1>", click)
f.pack()

# ----------------------------------------------------------------------------------------------------------

f = Frame(root, bg="grey")
b = Button(f, text="0", padx=14, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="/", padx=21, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="*", padx=18, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=5, pady=3)
b.bind("<Button-1>", click)
b = Button(f, text="=", padx=10, pady=5, font="Lucida 35 bold")
b.pack(side=LEFT, padx=4, pady=10)
b.bind("<Button-1>", click)
f.pack()

root.mainloop()






                                
     
   
                        
                      
                      


