in reply to Tab Key in Perl/Tk

I had the opposite problem a while back. I had a text field in which the tab key entered \t when I wanted it to shift focus. Simply using bind didn't work. Here is what I wound up doing:

my $t1 = $mw->Text( -background=>"navy", -foreground=>"white", -height=>35, -width=>80, -wrap=>"word", -selectbackground=>"blueviolet" ); $t1->bindtags( [ ($t1->bindtags)[1,0,2,3] ] ); + # fix the bindtags order so that widget events are + # processed before class events $t1->bind("<Tab>", sub { $t1->focusNext; Tk->break; }); + #Fix tab to shift focus, not print a tab.

Perhaps something similar is what you need.


--
Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'

Replies are listed 'Best First'.
Re^2: Tab Key in Perl/Tk
by Juthware (Novice) on Feb 25, 2005 at 16:32 UTC
    Thanks - I just wish I had your original problem because it seems to be the behaviour I want! I don't exactly understand your solution so I'll have to read up this. I think I've been too lucky with Perl/Tk so far - I've done a lot of stuff with no problems but I suppose it means I haven't had to look too hard at how things really work!

      Sorry. To explain my problem a bit better, I was binding Tab to the behaviour I desired, but I kept getting the undesired behaviour anyway. The bindtags line simply says "instead of checking bindings in the regular order (0,1,2,3), check them in the order that gives my binding precednece (1,0,2,3). (as the comment says, "so widget events are processed before class events")
      Of course, it's possible that the other reply to your post (bind prior to MainLoop) will be all you need. I was just tossing this out there in case that didn't solve your problem.


      --
      Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
      perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'