Basic Calc using Python Tkinter

 from tkinter import*


root=Tk()
root.geometry("300x520")
root.title("Calculator by Elalita")
scvalue=StringVar()
scvalue.set(" ")
screen=Entry(root, textvar=scvalue,font="lucida 40 bold")
screen.pack(fill =X,ipadx=8padx=10pady=10)
def click(event):
    global scvalue
    text=event.widget.cget("text")
    print(text)
    if text=="=":
        if  scvalue.get().isdigit():
            vlaue=int(scvalue.get())
        else:
            try:
                value=eval(screen.get())
            except Exception as Error:
                value="Error!"
            
        scvalue.set(value)
        screen.update()
    elif text=="C":
        scvalue.set("")
        screen.update()
    else:
        scvalue.set(scvalue.get()+text)
        screen.update()
f1=Frame(root,bg="grey")
b=Button(f1,text="9",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="8",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="7",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="+",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)
f1.pack()

f1=Frame(root,bg="grey")
b=Button(f1,text="6",padx=11pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="5",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="4",padx=11pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="-",padx=12pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)
f1.pack()

f1=Frame(root,bg="grey")
b=Button(f1,text="3",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="2",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="1",padx=12pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)

b=Button(f1,text="/",padx=12pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)
f1.pack()

f1=Frame(root,bg="grey")
b=Button(f1,text="x",padx=10pady=10,font="lucida 20  bold")
b.pack(side=RIGHT, padx=5pady=5 )
b.bind("<Button-1>", click)
b=Button(f1,text=".",padx=10pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5)
b.bind("<Button-1>", click)
b=Button(f1,text="0",padx=11pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5 )
b.bind("<Button-1>", click)
b=Button(f1,text="C",padx=10pady=10,font="lucida 20  bold")
b.pack(side=RIGHT, padx=5pady=5 )
b.bind("<Button-1>", click)
f1.pack()

f1=Frame(root,bg="grey")
b=Button(f1,text="=",padx=115pady=10,font="lucida 20  bold")
b.pack(side=LEFT, padx=5pady=5)
b.bind("<Button-1>", click)
f1.pack()

root.mainloop()
    


Comments

acclivity said…
How can I download this code? I don't think I can even see it all, as I can't scroll it sideways.
acclivity said…
This has obviously not been tested. You have a spelling mistake on line 14

Popular posts from this blog

Prime Number

star pattern