from tkinter import *
root = Tk()
def a():
e1.insert(END, '1')
def b():
e1.insert(END, '2')
def c():
e1.insert(END, '3')
def d():
e1.insert(END, '+')
def e():
e1.insert(END, '4')
def f():
e1.insert(END, '5')
def g():
e1.insert(END, '6')
def h():
e1.insert(END, '-')
def i():
e1.insert(END, '7')
def j():
e1.insert(END, '8')
def k():
e1.insert(END, '9')
def l():
e1.insert(END, '*')
def m():
e1.insert(END, '.')
def n():
e1.insert(END, '0')
def o():
x = eval(e1.get())
e2.delete(0, END)
e2.insert(0, x)
def p():
e1.insert(END, '/')
def AC():
e1.delete(0, END)
e2.delete(0, END)
Label(root, text='算式:').grid(row=0,column=0, columnspan=1, padx=5, pady=2)
Label(root, text='结果:').grid(row=1,column=0, columnspan=1, padx=5, pady=2)
e1 = Entry(root)
e2 = Entry(root)
e1.grid(row=0,column=1, columnspan=3, padx=5, pady=2)
e2.grid(row=1,column=1, columnspan=3, padx=5, pady=2)
Button(root, text='1', command=a).grid(row=2,column=0, padx=5, pady=2)
Button(root, text='2', command=b).grid(row=2,column=1, padx=5, pady=2)
Button(root, text='3', command=c).grid(row=2,column=2, padx=5, pady=2)
Button(root, text='加', command=d).grid(row=2,column=3, padx=5, pady=2)
Button(root, text='4', command=e).grid(row=3,column=0, padx=5, pady=2)
Button(root, text='5', command=f).grid(row=3,column=1, padx=5, pady=2)
Button(root, text='6', command=g).grid(row=3,column=2, padx=5, pady=2)
Button(root, text='减', command=h).grid(row=3,column=3, padx=5, pady=2)
Button(root, text='7', command=i).grid(row=4,column=0, padx=5, pady=2)
Button(root, text='8', command=j).grid(row=4,column=1, padx=5, pady=2)
Button(root, text='9', command=k).grid(row=4,column=2, padx=5, pady=2)
Button(root, text='乘', command=l).grid(row=4,column=3, padx=5, pady=2)
Button(root, text='▪', command=m).grid(row=5,column=0, padx=5, pady=2)
Button(root, text='0', command=n).grid(row=5,column=1, padx=5, pady=2)
Button(root, text='=', command=o).grid(row=5,column=2, padx=5, pady=2)
Button(root, text='除', command=p).grid(row=5,column=3, padx=5, pady=2)
Button(root, text=' AC ', command=AC).grid(row=6,column=0, columnspan=4, padx=5, pady=2)
mainloop()