Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: re-binding Tab in a TK Text field

by kelan (Deacon)
on Oct 30, 2004 at 06:02 UTC ( #403977=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://403977]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-09-29 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?