首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

计算器(python Tk编纂)

2012-12-20 
计算器(python Tk编写)from __future__ import divisionfrom Tkinter import Tk, Entry, Button, Label, m

计算器(python Tk编写)

from __future__ import division   from Tkinter import Tk, Entry, Button, Label, mainloop  from tkFont import Font  def pp(ev=None):      foodl = ''      try: foodl = eval( text.get())      except : pass      if isinstance(foodl, (int,float,long)): pass      else: foodl = 'Error..'      label.config(text=foodl)      #主窗口  top = Tk()  top.title('compute')    ft = Font(family = ('Verdana'), size = 8 ) #字体  #注册组件  text = Entry(top, font= ft)  button = Button(top, text='计算(注意先后运算)', 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()  

热点排行