Re: Disabling most bindings
- From: "Aric Bills" <aric.bills@xxxxxxxxx>
- Date: 22 Mar 2007 21:34:10 -0700
On Mar 22, 7:51 pm, "Plebeian" <casey.ack...@xxxxxxxxx> wrote:
Hi, I would like to disable all bindings in an entry widget, except
for numeric keys.
I have looked on the Wiki and search c.l.t, but I haven't come across
a solution.
I tried disabling all bindings, then enable the ones that I want, but
that is not practical and it also enters two instances of the number.
- Casey
One option is to filter out "normal" keypresses (e.g. excluding
backspace, delete, arrow keys, etc. which presumably should continue
to function as normal). This might do that job:
bind $entry <Key> {
if {[string length %K] == 1 && ![string is integer %K]} {
break
}
}
Alternatively, the entry widget provides the -validate option family (-
validate, -validatecommand, -invalidcommand).
A third option, if you want, would be to create a new bindtag, copy
all the bindings from Entry except for <Key>, and bind specifically to
the keys 0-9. Something like this:
foreach binding [bind Entry] {
bind NumEntry $binding [bind Entry $binding]
}
for {set i 0} {$i <= 9} {incr i} {
bind NumEntry <Key-$i> [bind Entry <Key>]
}
bind NumEntry <Key> {}
set tagnum [lsearch [bindtags $entry] "Entry"]
bindtags $entry [lreplace [bindtags $entry] $tagnum $tagnum NumEntry]
Regards,
Aric
.
- References:
- Disabling most bindings
- From: Plebeian
- Disabling most bindings
- Prev by Date: Disabling most bindings
- Next by Date: Re: Disabling most bindings
- Previous by thread: Disabling most bindings
- Next by thread: Re: Disabling most bindings
- Index(es):
Relevant Pages
|