from tkinter import*
def clear():
global ex
global label_show
result = "0"
ex=""
label_show.set(result)
def press(number):
global ex
global label_show
ex=ex+number
label_show.set(ex)
def equal ():
try:
global ex
global label_show
result=str(eval(ex))
label_show.set(result)
except:
result="ERROR"
ex=""
label_show.set(result)
t=Tk()
t.option_add("*font", "consolas 40")
label_show=StringVar()
label_show.set(0)
ex=""
Label(t,textvariable=label_show).grid(row=0,column=0,columnspan=4)
Button(t,text="clear",command=clear).grid(row=1,column=0,columnspan=4,sticky="news")
Button(t,text="7",command=lambda: press("7")).grid(row=2,column=0)
Button(t,text="8",command=lambda: press("8")).grid(row=2,column=1)
Button(t,text="9",command=lambda: press("9")).grid(row=2,column=2)
Button(t,text="/",command=lambda: press("/")).grid(row=2,column=3)
Button(t,text="4",command=lambda: press("4")).grid(row=3,column=0)
Button(t,text="5",command=lambda: press("5")).grid(row=3,column=1)
Button(t,text="6",command=lambda: press("6")).grid(row=3,column=2)
Button(t,text="*",command=lambda: press("*")).grid(row=3,column=3)
Button(t,text="1",command=lambda: press("1")).grid(row=4,column=0)
Button(t,text="2",command=lambda: press("2")).grid(row=4,column=1)
Button(t,text="3",command=lambda: press("3")).grid(row=4,column=2)
Button(t,text="-",command=lambda: press("-")).grid(row=4,column=3)
Button(t,text="0",command=lambda: press("0")).grid(row=5,column=0)
Button(t,text=".",command=lambda: press(".")).grid(row=5,column=1,columnspan=2,sticky="news")
Button(t,text="+",command=lambda: press("+")).grid(row=5,column=3)
Button(t,text="=",command=equal).grid(row=6,column=0,columnspan=4,sticky="news")
t.mainloop()\
รักเราไม่เก่าเลยBY yokky
def clear():
global ex
global label_show
result = "0"
ex=""
label_show.set(result)
def press(number):
global ex
global label_show
ex=ex+number
label_show.set(ex)
def equal ():
try:
global ex
global label_show
result=str(eval(ex))
label_show.set(result)
except:
result="ERROR"
ex=""
label_show.set(result)
t=Tk()
t.option_add("*font", "consolas 40")
label_show=StringVar()
label_show.set(0)
ex=""
Label(t,textvariable=label_show).grid(row=0,column=0,columnspan=4)
Button(t,text="clear",command=clear).grid(row=1,column=0,columnspan=4,sticky="news")
Button(t,text="7",command=lambda: press("7")).grid(row=2,column=0)
Button(t,text="8",command=lambda: press("8")).grid(row=2,column=1)
Button(t,text="9",command=lambda: press("9")).grid(row=2,column=2)
Button(t,text="/",command=lambda: press("/")).grid(row=2,column=3)
Button(t,text="4",command=lambda: press("4")).grid(row=3,column=0)
Button(t,text="5",command=lambda: press("5")).grid(row=3,column=1)
Button(t,text="6",command=lambda: press("6")).grid(row=3,column=2)
Button(t,text="*",command=lambda: press("*")).grid(row=3,column=3)
Button(t,text="1",command=lambda: press("1")).grid(row=4,column=0)
Button(t,text="2",command=lambda: press("2")).grid(row=4,column=1)
Button(t,text="3",command=lambda: press("3")).grid(row=4,column=2)
Button(t,text="-",command=lambda: press("-")).grid(row=4,column=3)
Button(t,text="0",command=lambda: press("0")).grid(row=5,column=0)
Button(t,text=".",command=lambda: press(".")).grid(row=5,column=1,columnspan=2,sticky="news")
Button(t,text="+",command=lambda: press("+")).grid(row=5,column=3)
Button(t,text="=",command=equal).grid(row=6,column=0,columnspan=4,sticky="news")
t.mainloop()\