I have an entry widget and I want only the numbers to be entered in this entry but not any other character from the keyboard. so cud some one point out some useful links of some procedures.
Use the "validate" and "validatecommand" options of the entry widget.
From the help file: VALIDATION
Validation works by setting the validateCommand option to a script which will be evaluated according to the validate option as follows:
none
Default. This means no validation will occur.
focus
validateCommand will be called when the entry receives or loses focus.
focusin
validateCommand will be called when the entry receives focus.
focusout
validateCommand will be called when the entry loses focus.
key
validateCommand will be called when the entry is edited.
all
validateCommand will be called for all above conditions.
It is possible to perform percent substitutions on the validateCommand and invalidCommand, just as you would in a bind script. The following substitutions are recognized:
%d
Type of action: 1 for insert, 0 for delete, or -1 for focus, forced or textvariable validation.
%i
Index of char string to be inserted/deleted, if any, otherwise -1.
%P
The value of the entry should edition occur. If you are configuring the entry widget to have a new textvariable, this will be the value of that textvariable.
%s
The current value of entry before edition.
%S
The text string being inserted/deleted, if any, {} otherwise.
%v
The type of validation currently set.
%V
The type of validation that triggered the callback (key, focusin, focusout, forced).
%W
The name of the entry widget.
In general, the textVariable and validateCommand can be dangerous to mix. Any problems have been overcome so that using the validateCommand will not interfere with the traditional behavior of the entry widget. Using the textVariable for read-only purposes will never cause problems. The danger comes when you try set the textVariable to something that the validateCommand would not accept, which causes validate to become none (the invalidCommand will not be triggered). The same happens when an error occurs evaluating the validateCommand.
Primarily, an error will occur when the validateCommand or invalidCommand encounters an error in its script while evaluating or validateCommand does not return a valid tcl boolean value. The validate option will also set itself to none when you edit the entry widget from within either the validateCommand or the invalidCommand. Such editions will override the one that was being validated. If you wish to edit the entry widget (for example set it to {}) during validation and still have the validate option set, you should include the command
after idle {%W config -validate %v}
in the validateCommand or invalidCommand (whichever one you were editing the entry widget from). It is also recommended to not set an associated textVariable during validation, as that can cause the entry widget to become out of sync with the textVariable.
thanx for the tip, but when using this {regsub -all {^[0-9]} $numsonly {} numsonly} command I'm not able to insert any character in my entry widget. I guess this expression blocked all the keys from the keyboard!!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.