码迷,mamicode.com
首页 > 编程语言 > 详细

Python3 Tkinter基础 Entry root.register包装函数 validatecommand中有 %P %v %W 传入当前的输入框的值及validate

时间:2017-01-28 00:28:21      阅读:620      评论:0      收藏:0      [点我收藏+]

标签:内容   div   and   images   class   content   roo   成就   false   

 镇场诗:
    清心感悟智慧语,不着世间名与利。学水处下纳百川,舍尽贡高我慢意。
    学有小成返哺根,愿铸一良心博客。诚心于此写经验,愿见文者得启发。
——————————————————————————————————————————

code:

from tkinter import *
root = Tk()



def test(content,reason,name):
	if content == "舍名利":
		print(‘正确‘)
		print(content, reason,name)
		return True
	else:
		print(‘错误‘)
		print(content, reason,name)
		return False

v=StringVar()
testCMD=root.register(test)#需要将函数包装一下,必要的
e1=Entry(root,
		 textvariable=v,
		 validate=‘focusout‘,
		 validatecommand=(testCMD,‘%P‘,‘%v‘,‘%W‘)
		 #%P表示 当输入框的值允许改变,该值有效。该值为当前文本框内容
		 #%v(小写大写不一样的),当前validate的值
		 #%W表示该组件的名字
		)

e1.pack()


mainloop()

 


result:

 

技术分享

 

============ RESTART: C:\Users\Administrator\Desktop\code_IDLE.py ============

 




P2技术分享

 

============ RESTART: C:\Users\Administrator\Desktop\code_IDLE.py ============
错误
博客园 focusout .53911680

 




P3技术分享

 

============ RESTART: C:\Users\Administrator\Desktop\code_IDLE.py ============
错误
博客园 focusout .53911680
正确
舍名利 focusout .53911680

 




  关闭窗体

============ RESTART: C:\Users\Administrator\Desktop\code_IDLE.py ============
错误
博客园 focusout .53911680
正确
舍名利 focusout .53911680
>>> 

 


——————————————————————————————————————————
博文的精髓,在技术部分,更在镇场一诗。Python版本3.5,系统 Windows7。
Python是优秀的语言,值得努力学习。我是跟着小甲鱼视频教程学习的,推荐。
我是一个新手,所以如果博文的内容有可以改进的地方,甚至有错误的地方,请留下评论,我一定努力改正,争取成就一个良心博客。
注:此文仅作为科研学习,如果我无意中侵犯了您的权益,请务必及时告知,我会做出改正。

Python3 Tkinter基础 Entry root.register包装函数 validatecommand中有 %P %v %W 传入当前的输入框的值及validate

标签:内容   div   and   images   class   content   roo   成就   false   

原文地址:http://www.cnblogs.com/jinlingzi/p/6354061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!