data entry validation with Tkinter

Ken Guest kwg at renre-europe.com
Tue Aug 7 06:03:26 EDT 2001


hi,
I'm trying to put together a python + tkinter app with data entry
validation.
What I have in mind is that the colour of the text changes depending
on what the user has typed. (In otherwords the text is displayed in
red if it is invalid, and in black if it is ok).
I'd like to use regex (or the more up-to-date re strings) to specify
what type of text is valid (cf my last query to the help mailing list).

At the moment, basic code that I have gotten to work looks like:

self.__entry = Entry(newframe, validate='key', vcmd='string is int %P',
invcmd='bell')

attempts at specifying python procedures for vcmd and invcmd only seem
to be called when the app in initialising and don't exactly work.
For example, with

self.__entry = Entry(newframe, validate='key', vcmd=self.validate('%P'),
invcmd=self.invalid())

the validate and invalid methods are called when the app starts up, but
neither of those methods are called when any keys are pressed, and I'm
really not sure that the second definition above is syntatically
correct, even though the parser didn't catch any problems.


What I'd like to know is if what I am looking to do is in anyway
possible, and if anybody has any pointers/ideas on how I could 
implement this functionality.
Am I left to using TCL expressions for data entry validation (and if so,
how do I do the above)


(I have done a number of searches on Google to see if anybody else
may have run into these questions before but couldn't find anything
of interest)

thanks,

Ken







More information about the Python-list mailing list