from tkinter import *
# commands
def btn1():
txt = entry.get()
entry.insert(INSERT, "1")
def btn2():
txt = entry.get()
entry.insert(INSERT, "2")
def btn3():
txt = entry.get()
entry.insert(INSERT, "3")
def btn4():
txt = entry.get()
entry.insert(INSERT, "4")
def btn5():
txt = entry.get()
entry.insert(INSERT, "5")
def btn6():
txt = entry.get()
entry.insert(INSERT, "6")
def btn7():
txt = entry.get()
entry.insert(INSERT, "7")
def btn8():
txt = entry.get()
entry.insert(INSERT, "8")
def btn9():
txt = entry.get()
entry.insert(INSERT, "9")
def cls():
entry.delete(0, END)
def answer_work():
res = eval(entry.get())
entry.delete(0, END)
entry.insert(INSERT, res)
def division_work():
entry.insert(INSERT, "/")
def plus_work():
entry.insert(INSERT, "+")
def minuse_work():
entry.insert(INSERT, "-")
def times_work():
entry.insert(INSERT, "*")
# app
app = Tk()
app.title("Grafical Calculator")
app.geometry("500x600")
app.resizable(0, 0)
# main entry
entry = Entry(app, bg="black", fg="white", width=90, font=("Arial", 16))
# all buttons
first = Button(app, text="1", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn1)
second = Button(app, text="2", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn2)
third = Button(app, text="3", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn3)
fourth = Button(app, text="4", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn4)
fifth = Button(app, text="5", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn5)
sixth = Button(app, text="6", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn6)
seventh = Button(app, text="7", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn7)
eighth = Button(app, text="8", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn8)
nineth = Button(app, text="9", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=btn9)
clear = Button(app, text="clear", bg="gray", fg="white", width=9, height=5, font=("Arial", 16), command=cls)
answer = Button(app, text="=", bg="gray", fg="white", width=9, height=11, font=("Arial", 16), command=answer_work)
division = Button(app, text="÷", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=division_work)
plus = Button(app, text="+", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=plus_work)
minuse = Button(app, text="-", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=minuse_work)
times = Button(app, text="x", bg="gray", fg="white", width=10, height=5, font=("Arial", 16), command=times_work)
# placing
entry.place(relx=0, rely=0, height=70)
first.place(relx=0, rely=0.115)
second.place(relx=0.26, rely=0.115)
third.place(relx=0.52, rely=0.115)
fourth.place(relx=0, rely=0.345)
fifth.place(relx=0.26, rely=0.345)
sixth.place(relx=0.52, rely=0.345)
seventh.place(relx=0, rely=0.575)
eighth.place(relx=0.26, rely=0.575)
nineth.place(relx=0.52, rely=0.575)
clear.place(relx=0.78, rely=0.115)
answer.place(relx=0.78, rely=0.345)
plus.place(relx=0.0, rely=0.805)
minuse.place(relx=0.26, rely=0.805)
times.place(relx=0.52, rely=0.805)
division.place(relx=0.78, rely=0.815)
app.mainloop()