I'm including a scrolled text box widget in my main Tk window which I have set up to intercept any key presses as follows:
use Tk;
use Tk::ROText; # read-only version of Text widget
$mw = new Tk::MainWindow;
$textBox = $mw->Scrolled('ROText', -scrollbars =>'e')->grid();
$mw->bind('<Any-KeyPress>' => \&key_handler);
#Attempts to disable key bindings of text widget
#$textBox->bind('<Any-KeyPress>' => sub {});
#$textBox->bindtags(undef);
Tk::MainLoop;
sub key_handler {
$count++;
$textBox->insert('end', "key press #$count\n");
}
The Text widget has a bunch of default key bindings, among them is moving the cursor with the arrow keys. I want to disable this behavior, since I wish to execute some other actions based on the arrow keys.
I tried $textBox->bind('Any-KeyPress' => sub {});
and $textBox->bindtags(undef);
based on suggested solutions I found online, but neither would disable the cursor movement inside the text box. I still get the undesired cursor movement in addition to the desired key_handler
calls.
Are there any other suggestions as to how I can disable Text widget keyboard bindings?