[Tutor] Query about using Pmw entry widget...

Luke Paireepinart rabidpoobear at gmail.com
Sun Jan 7 22:27:16 CET 2007

Alan Gauld wrote:
> "Luke Paireepinart" <rabidpoobear at gmail.com> wrote
> OP>> Can some one help me how to add validation : only integers are 
> allowed
> OP>> and minimum value should be 1.
> OP>>
> OP>> timeInterval = Pmw.EntryField(label_text='Time Interval(in
> OP>> sec.):',labelpos='w',validate = 'numeric')
> I don;t have PMW installed. I tend to use Tix now that its part
> of standard Python. However Grayson says this:
> "validation is [performed by a function which takes
> as its first argument the entered text and returns
> one of three standard values...
> So it seems you need
> def numeric(val):
>     try: float(val)
>     except ValueError: return Pmw.ERROR
>     else: return Pmw.OK
> timeinterval = Pmw.EntryField(.....validate=numeric)
> At least that's how I read it, obviously without Pmw I can't try it...
>>> Also I want to validate date and time? I know that there is a way 
>>> to
>>> do it but I dont know the exact syntax..
> I'd use a similar technique as above. parse the string and try
> to create a datetime object then handle the exceptions.
> Luke> it's a lot easier to validate the input when you're using it 
> instead of
> Luke> trying to restrict their input.
> Its easier for the programmer but much worse for the user.
> We should always catch erroneous input as early as possible.
> Early CGI Web pages were the classic example of late error
> handling and there is nothing more annoying than filling in a form,
> submitting it and then being told you filled in a field wrong right
> at the start!

The difference between a webpage and an application here is that if the 
user enters something incorrectly,
he'll know as soon as he tries to submit it,
without having to wait for the page to reload,
and he won't lose all of his information just to go back and change one 
But I guess I don't know anything about UI design.
That's why I just purchased 'The Essential Guide To User Interface 
Design' from Half-Price Books!
Yes, a bit of a strange coincidence that I bought it just today.

I know it's frustrating to have to go back to fix entries,
but it's also annoying to have something restrict your input.
That seems sort of like the programmer didn't want to take the time to 
have a robust user input parser :D
I think the ideal situation for me would be that whenever an entry 
widget loses focus, the validate() function is called,
and I get some kind of visual warning that my entry is incorrect.
NOT a dialog box, I hope, but some kind of red warning label next to the 
entry widget or something.
However, this doesn't work for the last entry on the page, because most 
likely focus will switch straight from the entry to the submit button,
but then the whole 'check on submit' thing would catch the error.
Basically I don't want to see an entry box that behaves differently than 
a normal entry box (only accepts integers, for example).

> HTH,

More information about the Tutor mailing list