Interactively validating Entry widget content in tkinter
the link above explains how to do validation.
I am trying to do the same thing. But somehow i am not able to do it.
It is a 10 digit string. The first two being alphabets, the next two numbers then again the next two will be alphabets and then the rest all numbers. for example MH02UH2012.
Other question which i have is when i run this the print of S and i is coming for the first three inputs only after that there is no print. and sometimes it prints only the first entered variable. I am not able to understand what is the issue
import tkinter
tk=tkinter.Tk()
def only_numeric_input(P,S,i):
i = int(i)
print (i, S)
if S == " ":
return False
elif i < 2:
if not S.isdigit():
return True
elif i > 5:
if S.isdigit():
return True
else:
return False
elif i > 9:
return False
e1=tkinter.Entry(tk)
e1.grid(row=0,column=0)
c=tk.register(only_numeric_input)
e1.configure(validate="key",validatecommand=(c,'%P', "%S", "%i"))
tk.mainloop()