Tkinter Entry only allows digit number

来源:互联网 发布:u盘损坏数据恢复 编辑:程序博客网 时间:2024/05/25 23:56
from Tkinter import *def validatecontent(S):    print "S='%s'" % S    return (S.isdigit()==bool(S))   #can only input digit number,and must use this format  **S**==**S**vcmd=(top.register(validatecontent),'%S')   #use S,the text string being inserted# valid percent substitutions (from the Tk entry man page)# %d = Type of action (1=insert, 0=delete, -1 for others)# %i = index of char string to be inserted/deleted, or -1# %P = value of the entry if the edit is# %s = value of entry prior to editing# %S = the text string being inserted or deleted, if any# %v = the type of validation that is currently set# %V = the type of validation that triggered the callback#      (key, focusin, focusout, forced)# %W = the tk name of the widgetentry2=Entry(top,textvariable=e2,validate='all',validatecommand=vcmd)entry2.pack()
top.mainloop()

0 0