|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
关于这个有两个不明白,1:.grid()这个的作用,不是很清楚,2,状态设置,感觉没什么变化,validate="focusout",validatecommand=test
谢谢大家解决,
- from tkinter import *
- root = Tk()
- #e.delete(0,END)
- #e.insert(0,"默认文本....")
- Label(root,text="作者").grid(row=0,column=0)
- Label(root,text="作品").grid(row=1,column=0)
- def test():
- if e1.get() == "零基础入门学习python":
- print("正确")
- return True
- else:
- print("错误")
- e1.delete(0,END)
- return False
-
- v1 = StringVar()
- v2 = StringVar()
- e1 = Entry(root,textvariable = v1,validate="focusout",validatecommand=test)
- e2 = Entry(root,textvariable = v2,show="*")
- e1.grid(row = 0,column = 1,padx = 5,pady = 5)
- e2.grid(row = 1,column = 1,padx = 5,pady = 5)
- def show():
- print("作者:《%s》" % e1.get())
- print("作品:《%s》" % e2.get())
-
- Button(root,text="获取信息",width=10,command=show)\
- .grid(row=3,column=0,sticky=W,padx=10,pady=5)
- Button(root,text="退出",width=10)\
- .grid(row=3,column=1,sticky=E,padx=10,pady=5)
- mainloop()
复制代码
grid可以对控件坐标进行设置,坐标点以行,列表示。即用来设置各个控件放在根窗口的什么位置。
validate="focusout",validatecommand=test从字面意思可以看出,如果前半句为真,则执行后半句。即若验证为focusout(失去焦点),则执行test。其他的我就不知道了。
|
|