from tkinter import *
expression = ""

def press(num):
    global expression
    expression = expression + str(num)
    equation.set(expression)

def equalpress():
    global expression
    total = str(eval(expression)) # eval(2+3*8)
    equation.set(total)
    expression = ""

def clear():
    global expression
    expression = ""
    equation.set("")

gui = Tk()
gui.title("Simple Calculator")
gui.geometry("250x130")

equation = StringVar()

expression_field = Entry(gui, textvariable=equation)
expression_field.grid(columnspan=2)

button1 = Button(gui, text=' 1 ', fg='black', bg='red', command=lambda: press(1), height=1, width=7)
button1.grid(row=2, column=0)

button2 = Button(gui, text=' 2 ', fg='black', bg='red', command=lambda: press(2), height=1, width=7)
button2.grid(row=2, column=1)

plus = Button(gui, text=' + ', fg='black', bg='red', command=lambda: press("+"), height=1, width=7)
plus.grid(row=3, column=0)

equal = Button(gui, text=' = ', fg='black', bg='red', command=equalpress, height=1, width=7)
equal.grid(row=3, column=1)

clear = Button(gui, text='Clear', fg='black', bg='red', command=clear, height=1, width=7)
clear.grid(row=4, column=0)

# start the GUI
gui.mainloop()
