http://qs321.pair.com?node_id=403977


in reply to re-binding Tab in a TK Text field

Ok, this is kind of tricky, but possible. In Tcl, you could do it like this:

bind .t1 <Tab> { focus [tk_focusNext .t1]; break }
So you might think that a straight translation of that would work for Perl/Tk, but it doesn't. (I tried it.)

The reason that a straight translation doesn't work is because Perl/Tk changed the default order that bindtags uses. To change the binding, either subclass and change it, as suggested above, or simply reorder the bindtags for the widget and then you can do the rebind:

# fix the bindtags order so that widget events are # processed before class events $t1->bindtags( [ ($t1->bindtags)[1,0,2,3] ] ); # now give the text widget a new Tab binding $t1->bind( '<Tab>', sub { $t1->focusNext; Tk->break; } );
If you're observant, you'll also notice one other place where it wasn't a straight translation. In Tcl, tk_focusNext just returns the name of the next widget in focus order, then you have to actually call focus on it. In Perl/Tk, it just sets the focus directly.

Replies are listed 'Best First'.
Re^2: re-binding Tab in a TK Text field
by wolfger (Deacon) on Nov 03, 2004 at 15:00 UTC
    Thanks! That does the trick, and is a lot easier than subclassing.

    --
    Believe nothing, no matter where you read it, or who said it - even if I have said it - unless it agrees with your own reason and your own common sense.
    (Buddha)