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

Tk::Notebook exclude tab from focus traversal

by cscvrp (Novice)
on Nov 26, 2018 at 08:09 UTC ( #1226322=perlquestion: print w/replies, xml ) Need Help??

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

I've got a use case where I have a few Entry widgets with one of them infrequently modified and excluded from the tab key focus traversal. I have found need to add a Notebook to this with all existing widgets etc in page1, some new things on page2. I can't seem to exclude the page tabs from the tab key focus traversal... Maybe you can't? This will cramp my style enough to drop the Notebook if thats the case, so I want to make sure its not just user error. Here is an example, desired behavior is just to tab between the top three Entry only.
use strict; use warnings; use Tk; require Tk::NoteBook; my $main = MainWindow->new( ); my $nb = $main->NoteBook(-takefocus => 0 )->pack(-expand => 1, -fill = +> 'both'); my $page1 = $nb->add('page1', -label => 'Page 1'); $page1->Entry()->pack(); $page1->Entry()->pack(); $page1->Entry()->pack(); $page1->Entry(-takefocus => 0)->pack(); $nb->add('page2', -label => 'Page 2'); MainLoop;
Thanks

Replies are listed 'Best First'.
Re: Tk::Notebook exclude tab from focus traversal
by tybalt89 (Prior) on Nov 26, 2018 at 08:36 UTC

    Quick hack before I go to bed.

    #!/usr/bin/perl # https://perlmonks.org/?node_id=1226322 use strict; use warnings; use Tk; require Tk::NoteBook; my $main = MainWindow->new( ); my $nb = $main->NoteBook(-takefocus => 0 )->pack(-expand => 1, -fill = +> 'both'); my $page1 = $nb->add('page1', -label => 'Page 1'); my $one = $page1->Entry()->pack(); $page1->Entry()->pack(); $page1->Entry()->pack(); my $four = $page1->Entry(-takefocus => 1)->pack(); $four->bind('<FocusIn>' => sub {$one->focus} ); $nb->add('page2', -label => 'Page 2'); MainLoop;
Re: Tk::Notebook exclude tab from focus traversal
by beech (Parson) on Nov 27, 2018 at 02:07 UTC

    Hi

    Use

    $nb->configure( -takefocus, 0 );
      Wow, I must have danced around that for an hour without hitting it. Thats exactly what i expected to find, thanks for taking the time.
Re: Tk::Notebook exclude tab from focus traversal
by tybalt89 (Prior) on Nov 26, 2018 at 21:20 UTC

    Here's a version that allows shift-tab to go backwards properly, that is, it works both forward and backwards.

    #!/usr/bin/perl # https://perlmonks.org/?node_id=1226322 use strict; use warnings; use Tk; require Tk::NoteBook; my $main = MainWindow->new( ); my $nb = $main->NoteBook(-takefocus => 0 )->pack(-expand => 1, -fill = +> 'both'); my $page1 = $nb->add('page1', -label => 'Page 1'); my $one = $page1->Entry()->pack(); $page1->Entry()->pack(); my $three = $page1->Entry()->pack(); $page1->Entry()->pack(); $three->bind('<Tab>' => sub { $main->after( 0, sub {$one->focus} ) } ) +; $one->bind('<<LeftTab>>' => sub { $main->after( 0, sub {$three->focus} + ) } ); $nb->add('page2', -label => 'Page 2'); MainLoop;
      While it turns out the takefocus works if you just apply it to the right place as beech shows, this was very helpful in helping me think about managing focus, and I'm going to need this soon in some soon to tackle problems elsewhere. Thanks for your time, much appreciated!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1226322]
Approved by Athanasius
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2021-10-25 13:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?