from tkinter import *
root=Tk()
root.title('计算器')
def run1():
a=float(inp1.get())
b=float(inp2.get())
s='%.2f+%.2f=%.2f\n'%(a,b,a+b)
txt.insert(END,s)
inp1.delete(0,END)
inp2.delete(0,END)
def run2():
a=float(inp1.get())
b=float(inp2.get())
s='%.2f-%.2f=%.2f\n'%(a,b,a-b)
txt.insert(END,s)
inp1.delete(0,END)
inp2.delete(0,END)
def run3():
a=float(inp1.get())
b=float(inp2.get())
s='%.2f*%.2f=%.2f\n'%(a,b,a*b)
txt.insert(END,s)
inp1.delete(0,END)
inp2.delete(0,END)
def run4():
a=float(inp1.get())
b=float(inp2.get())
s='%.2f/%.2f=%.2f\n'%(a,b,a/b)
txt.insert(END,s)
inp1.delete(0,END)
inp2.delete(0,END)
lb1=Label(root,text='请输入两个数,按下面按钮进行计算')
lb1.pack()
txt1=Entry(root)
txt2=Entry(root)
txt1.pack()
txt2.pack()
bt1=Button(root,text='加法',command=run1)
bt2=Button(root,text='减法',command=run2)
bt3=Button(root,text='乘法',command=run3)
bt4=Button(root,text='除法',command=run4)
bt1.pack()
bt2.pack()
bt3.pack()
bt4.pack()
txt=Text(root)
txt.pack()
root.mainloop()