-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculator.py
1 lines (1 loc) · 1.48 KB
/
calculator.py
1
calculator=[exec("from tkinter import *"),(window := Tk()),(window.title("calculator")),(window.configure(background="black")),(window.resizable(width=False,height=False)),(window.geometry("585x678+0+0")),(calc:=Frame(window, relief=FLAT)),(calc.grid()),(txtd:=Text(calc,font=('arial', 20),bg="white",height=2, width=33)),(txtd.grid(row=0,column=0,columnspan=6,pady=1)),(txtd.insert(1.0,"0")),(calculation:=""),(cur_cal := lambda button: [globals().update(calculation = calculation+str(button)),txtd.delete(1.0,"end"),txtd.insert(1.0,calculation)]),(tryExcept := lambda condition1, condition2: exec(f"try:{condition1}] \nexcept:{condition2}")),(clear := lambda : [globals().update(calculation = " "),txtd.delete(1.0,"end")]),(evaluate := lambda: tryExcept('[print(calculation),(res:=eval(calculation)),print(res),(globals().update(calculation = str(res))),(txtd.delete(1.0,"end")),(txtd.insert(1.0,calculation))','[(clear()),(txtd.insert(1.0,"error"))]')),(btn:=['+','*','/',7,8,9,4,5,6,1,2,3,'.',0,'-']),(i:=0),([[[Button(calc,width=6,height=3,font=('arial',20,'bold'),bd=4,bg="#873e23",text=btn[i],command=lambda button=btn[i]:cur_cal(button)).grid(row=j,column=k),(i:=i+1)] for k in range(3)] for j in range(2,7)]),(btnc:=Button(calc,width=6,height=3,font=('arial',20,'bold'),bd=4,bg="#E6d3cb",text="C",command=lambda:clear()).grid(row=2,column=3)),(btneq:=Button(calc,width=6,height=3,font=('arial',20,'bold'),bd=4,bg="#F3ae0c",text="=",command=lambda:evaluate()).grid(row=6,column=3)),(window.mainloop())]