[Tkinter-discuss] validating an entry
Jeff Cagle
jrcagle at juno.com
Tue Aug 22 05:03:57 CEST 2006
So it turned out that validating was not too hard, but you had to Google
for the documentation. Your name, Cameron, showed up a couple of times...
Here's the code:
# Testing an edit box with validation
from Tkinter import *
class MyEntry(Entry):
def __init__(self, master, maxchars):
Entry.__init__(self, master, validate = "key",
validatecommand=self.validatecommand)
self.MAX = maxchars
def validatecommand(self, *args):
return len(self.get()) < self.MAX
if __name__ == '__main__':
tkmain = Tk()
e = MyEntry(tkmain, 5)
e.grid()
tkmain.mainloop()
The validatecommand has to return a Boolean. I have no idea of the
following, and haven't been able to find answers yet online:
1) what args are passed to validatecommand? Obviously *args scoops them
up, but would one ever want to use them?
2) what values other than "key" are acceptable to validate?
Thanks,
Jeff Cagle
More information about the Tkinter-discuss
mailing list