#coding=utf-8
from __future__ import division
from Tkinter import Tk,Entry,Button,Label,mainloop
from tkFont import Font
def pp(ev=None):
food1=''
try:fond1=eval(text.get())
except:pass
if isinstance(food1,(int,float,long)):pass
else:food1='error..'
label.config(text=fond1)
top=Tk()
top.title('computer')
ft=Font(family=('Verdana'),size=8)
text=Entry(top,font=ft)
button=Button(top,text='computer',command=pp)
label=Label(text='+-',font=ft)
Enter=lambda x:x.keycode==13 and pp()
Key=lambda x:label.config(text='+-')
text.bind('Key',Enter)
text.focus()
text.bind('<Button-1>',Key)
text.pack()
button.pack()
label.pack()
mainloop()
python最简单的计算器
最新推荐文章于 2024-06-20 10:40:26 发布