Keep It Simple, Stupid | |
PerlMonks |
Re: Tk::Entry validate questionby graff (Chancellor) |
on Jun 16, 2002 at 04:54 UTC ( [id://174899]=note: print w/replies, xml ) | Need Help?? |
Maybe it would be appropriate to use two different variables;
one for the Entry "-textvariable", and another for the Scale
"-variable"; then, use callbacks to keep the two in sync --
something like this:
Here, the "-command" callback of the Scale widget will update the "-textvariable" of the Entry widget whenever the Scale is adjusted manually -- works just as well as using the same variable for both widgets. When the user decides to type a value into the Entry to control the Scale position, this approach requires that the "<Return>" key be used to signal that the user is done editing the Entry content and the string value is ready for application to the Scale variable. The binding of the "<Return>" event in the Entry widget will handle the validation -- checking not only that it is all digits, but also that the (integer) number value falls within the min-max range for the Scale widget. Personally, I tend to prefer this sort of approach for using strings in an Entry -- let users make as many edit operations as they want, of whatever sort, so long as they issue an explicit event once they decide that the string value is ready for use. Tk::Entry's "validate" mechanism does not support this sort of trigger -- I suppose because it would be redundant, since "bind" does this perfectly well. update: I know a lot of people do prefer instant feedback, so instead of binding on the "<Return>" event, one could instead bind on "<KeyRelease>", and change (simplify) the callback slightly: In this case, the Entry variable is simply ignored if it is empty or contains invalid data; otherwise, it is applied to the Scale variable
In Section
Seekers of Perl Wisdom
|
|