#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
from Tkinter import *
from tkFont import Font
def btnClick(ev = None):
foodl = ''
try:
foodl = eval(en.get())
except:
pass
if isinstance(foodl, (int, float, long)):
pass
else:
foodl = 'Error..'
lbl.config(text = foodl)
#主窗口
mainView = Tk()
mainView.title('YuanLin')
ft = Font(family = ('Verdana'), size = 18)
en = Entry(mainView, font = ft)
btn = Button(mainView, text = '计算(注意运算顺序)', command = btnClick, font = ft)
lbl = Label(text = '运算符: + - * / % **', font = ft)
enterEvent = lambda x: x.keycode == 13 and btnClick()
clickEvent = lambda x: lbl.config(text = '运算符: + - * / % **')
en.focus()
en.bind('<Key>', enterEvent)
en.bind('<Button-1>', clickEvent)
en.pack()
btn.pack()
lbl.pack()
mainView.mainloop()
|