标签:
1 from tkinter import * 2 3 master = Tk() 4 5 frame = Frame(master) 6 frame.pack(padx=10,pady=10) 7 8 v1 = StringVar() 9 v2 = StringVar() 10 v3 = StringVar() 11 def test(content): 12 return content.isdigit() 13 14 testCMD=master.register(test) 15 16 e1=Entry(frame,width=10,textvariable=v1,validate="key",17 validatecommand=(testCMD,‘%P‘)).grid(row=0,column=0) 18 19 Label(frame,text="+").grid(row=0,column=1) 20 21 e2=Entry(frame,width=10,textvariable=v2,validate="key",22 validatecommand=(testCMD,‘%P‘)).grid(row=0,column=2) 23 24 Label(frame,text="=").grid(row=0,column=3) 25 26 e3=Entry(frame,width=10,textvariable=v3,state="readonly").grid(row=0,column=4) 27 28 29 def calc(): 30 result = int(v1.get()) + int(v2.get()) 31 v3.set(str(result)) 32 33 Button(frame,text="计算结果",command=calc).grid(row=1,column=2,pady=5) 34 mainloop()
标签:
原文地址:http://www.cnblogs.com/tkinter/p/5629598.html