brian42miller has asked for the wisdom of the Perl Monks concerning the following question:

Hello There,

If I have a text widget ....

my $text = $frame->Scrolled('Text',-state => 'disabled');

and I try to bind a key event to it

$text->Subwidget("text")->bind( '<Any-Key>' => sub { print "HELLO\n"; });

the key event does not seem to get recognized if the -state is 'disabled'. When I set the -state to 'normal' the event does get recognized.

I am using the text widget as a transcript window so I don't want it 'normal'.

Is there a anyway to catch a key event over a disabled text widget?

Thanks Brian

Replies are listed 'Best First'.
Re: Tk Text widget & key bindings
by lamprecht (Friar) on Apr 20, 2011 at 20:34 UTC

    Your text widget needs focus to receive key events. Configure  -takefocus => 1 or give it focus calling  $text->focus().

    Cheers, Christoph
    use warnings; use strict; use Tk; my $t=tkinit->Text(-state => 'disabled', -takefocus =>1, # tab-key moves focus )->pack; $t->bind('<Any-Key>'=>sub { print "received Key\n"; }); $t->focus; #init focus MainLoop;
      Yes, thank you, that did the trick. Greatly appreciate the help! Brian