#coding:utf-8
from Tkinter import *
class App:
def __init__(self,root):
#定义帧
frame = Frame(root)
frame.pack()
self.frame = frame
w = Label(frame,text = "calculator")
w.pack()
self.newinput()
#调用回调函数
button1 = Button(frame,text='1',fg="red",command = lambda : self.buttoncb(1))
button1.pack()
button2 = Button(frame,text='2',fg="red",command = lambda : self.buttoncb(2))
button2.pack()
button = Button(frame,text='Quit',fg="red",command = root.quit)
button.pack()
def newinput(self):
v = StringVar()
e = Entry(self.frame,textvariable = v)
self.v = v
e.pack()
#定义回调函数
def buttoncb(self,i):
#print "button"
val = self.v.get()
self.v.set(val+str(i))
root=Tk()
a = App(root)
root.mainloop()
from Tkinter import *
class App:
def __init__(self,root):
#定义帧
frame = Frame(root)
frame.pack()
self.frame = frame
w = Label(frame,text = "calculator")
w.pack()
self.newinput()
#调用回调函数
button1 = Button(frame,text='1',fg="red",command = lambda : self.buttoncb(1))
button1.pack()
button2 = Button(frame,text='2',fg="red",command = lambda : self.buttoncb(2))
button2.pack()
button = Button(frame,text='Quit',fg="red",command = root.quit)
button.pack()
def newinput(self):
v = StringVar()
e = Entry(self.frame,textvariable = v)
self.v = v
e.pack()
#定义回调函数
def buttoncb(self,i):
#print "button"
val = self.v.get()
self.v.set(val+str(i))
root=Tk()
a = App(root)
root.mainloop()

本文介绍了一个使用Python Tkinter库创建的简易计算器应用程序。该程序包含一个输入框用于显示计算表达式,以及数字按钮1和2,点击按钮可以在输入框中追加对应的数字。此外,还提供了一个退出按钮来关闭程序。
671

被折叠的 条评论
为什么被折叠?



