import tkinter
root=tkinter.Tk()
root.title(“计算器”)#窗体标题
s=’’
def count(self):
global s
if self!=’=’:
lb.config(text=self)
s=s+self
else:
if “+” in s:
lb.config(text=(float(s.split("+")[0]) + float(s.split("+")[1]))) # 分割输入的计算公式
s=’’
if “-” in s:
lb.config(text=(float(s.split("-")[0]) - float(s.split("-")[1]))) # 分割输入的计算公式
s=’’
if “" in s:
lb.config(text=(float(s.split("”)[0]) * float(s.split("*")[1]))) # 分割输入的计算公式
s=’’
lb=tkinter.Label(root,text="",bg=“yellow”,width=20,anchor=‘e’)#生成标签
lb.grid(row=0,column=0,columnspan=4)
button7= tkinter.Button(root,text=‘7’,width=3,command=lambda:count(‘7’)).grid(row=1,column=0,padx=3)
button8= tkinter.Button(root,text=‘8’,width=3,command=lambda:count(‘8’)).grid(row=1,column=1,padx=3)
button9= tkinter.Button(root,text=‘9’,width=3,command=lambda:count(‘9’)).grid(row=1,column=2,padx=3)
button10= tkinter.Button(root,text=’’,width=3,command=lambda:count(’’)).grid(row=1,column=3,padx=3)
button4= tkinter.Button(root,text=‘4’,width=3,command=lambda:count(‘4’)).grid(row=2,column=0,padx=3)
button5= tkinter.Button(root,text=‘5’,width=3,command=lambda:count(‘5’)).grid(row=2,column=1,padx=3)
button6= tkinter.Button(root,text=‘6’,width=3,command=lambda:count(‘6’)).grid(row=2,column=2,padx=3)
button11=tkinter.Button(root,text=’-’,width=3,command=lambda:count(’-’)).grid(row=2,column=3,padx=3)
button1= tkinter.Button(root,text=‘1’,width=3,command=lambda:count(‘1’)).grid(row=3,column=0,padx=3)
button2= tkinter.Button(root,text=‘2’,width=3,command=lambda:count(‘2’)).grid(row=3,column=1,padx=3)
button3= tkinter.Button(root,text=‘3’,width=3,command=lambda:count(‘3’)).grid(row=3,column=2,padx=3)
button12=tkinter.Button(root,text=’+’,width=3,command=lambda:count(’+’)).grid(row=3,column=3,padx=3)
button0= tkinter.Button(root,text=‘0’,width=9,command=lambda:count(‘0’)).place(y=113,x=2)
button13= tkinter.Button(root,text=’.’,width=3,command=lambda:count(’.’)).grid(row=4,column=2,padx=3)
button14= tkinter.Button(root,text=’=’,width=3,command=lambda:count(’=’)).grid(row=4,column=3,padx=3)
root.mainloop()#进入消息循环