简单的计算器(python)

from Tkinter import *
def foo():
    input = var.get()
    try:
        c = eval(input)
    except:
        c = "error!"
    t.config(text = "结果是: " + str(c))

root = Tk()
root.title("小小计算器")

#btn
button = Button(root, text="计算结果", command = foo)
button.grid(column=2, row=1, sticky=E)

#input
var = StringVar()
widget = Entry(textvariable=var)
widget.grid(column=1, row=1, sticky=W)

#result
t = Label(root,text = "结果是: ")
t.grid(column=1, row=2, sticky=W,)

root.mainloop()

 

posted @ 2014-02-11 18:04  WINSTON-DEAN  阅读(186)  评论(0编辑  收藏  举报