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 widget
entry2=Entry(top,textvariable=e2,validate='all',validatecommand=vcmd)
entry2.pack()