Re: Disabling most bindings



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

.



Relevant Pages

  • setting an attribute
    ... "When you bind an attribute whose ... It looks to me like self.xis binding on an instance whose ... entry for the attribute in the instance--instead it is affecting a ...
    (comp.lang.python)
  • Re: strategy for data entry in multiple tables
    ... I sometimes use composite keys to prevent duplicates in a table, ... > what appears to be excess entry is necessary for data validation and for ... > tables be opened as subforms within the junction table form? ... >> the bird info...just the info necessary to determine whether the bird ...
    (microsoft.public.access.forms)
  • Re: Menu accelerators
    ... Also, check that if the Caps Lock is activated, the binding does ... >> moved this app to a laptop, I found that when I tried to copy or paste ... >> control and C or control and V keys, ... > the -accelerator flag only afect the little label that is drawn ...
    (comp.lang.tcl)
  • Re: associative array, container, mapping, terminology
    ... | struct key_and_value { ... I wrote a mapping library in C. ... of storing a value into an entry. ... Suppose we decided to represent keys thusly: ...
    (comp.programming)
  • Re: DNSSEC auto-dnssec issue bind-9.7.2-P3
    ... BIND isn't signing. ... I have my test zone example configured with option auto-dnssec maintain; ... and I've configured keys with timing options: ...
    (comp.protocols.dns.bind)