Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Tab Order for Widgets in HList

by zentara (Archbishop)
on Oct 19, 2011 at 14:01 UTC ( [id://932413]=note: print w/replies, xml ) Need Help??


in reply to Tab Order for Widgets in HList

Not to hijack the thread, but I ran into some Tab troubles when trying to work on this problem. The code below is supposed to be a general purpose routine for defining focus order, but if you try it, it works for the Enter key, but not Tab! Can anyone enlighten me as to why Tab is hard coded to pass focus the way it does?
#!/usr/bin/perl use Tk; use strict; use warnings; #changes focus on Return(Enter) key but not Tab my $win = MainWindow->new(); my $foo = $win->Entry->pack; my $bar = $win->Entry->pack; my $baz = $win->Entry->pack; my $boo = $win->Entry->pack; my $baa = $win->Entry->pack; &defineOrder($foo,$baa,$bar,$boo,$baz); sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind('<Key-Return>', [\&focus, $_[$i+1]]); # won't work with Tab $_[$i]->bind('all', '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[$#_]->bind('<Key-Return>', [\&focus, $_[0]]); $_[0]->focus; } sub focus { my ($tk, $self) = @_; $self->focus; } MainLoop();

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Tab Order for Widgets in HList
by Anonymous Monk on Oct 19, 2011 at 14:59 UTC

    I'm not sure what is going on, but its something :)

    tab x 5, enter x 10

    MainWindow=HASH(0xe911ac) bindtags ( MainWindow , . , all , ) Tk::Entry=HASH(0xed9414) bindtags ( Tk::Entry , .entry , . , all , ) Tk::Entry=HASH(0xed96b4) bindtags ( Tk::Entry , .entry4 , . , all , ) Tk::Entry=HASH(0xed95f4) bindtags ( Tk::Entry , .entry1 , . , all , ) Tk::Entry=HASH(0xed9664) bindtags ( Tk::Entry , .entry3 , . , all , ) Tk::Entry=HASH(0xed9644) bindtags ( Tk::Entry , .entry2 , . , all , ) MainWindow=HASH(0xe911ac) = $win Tk::Entry=HASH(0xed9414) = $foo Tk::Entry=HASH(0xed95f4) = $bar Tk::Entry=HASH(0xed9644) = $baz Tk::Entry=HASH(0xed9664) = $boo Tk::Entry=HASH(0xed96b4) = $baa focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9414) focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed96b4) focus Tk::Entry=HASH(0xed96b4) Tk::Entry=HASH(0xed95f4) focus Tk::Entry=HASH(0xed95f4) Tk::Entry=HASH(0xed9664) focus Tk::Entry=HASH(0xed9664) Tk::Entry=HASH(0xed9644) focus Tk::Entry=HASH(0xed9644) Tk::Entry=HASH(0xed9414) focus Tk::Entry=HASH(0xed9414) Tk::Entry=HASH(0xed96b4) focus Tk::Entry=HASH(0xed96b4) Tk::Entry=HASH(0xed95f4) focus Tk::Entry=HASH(0xed95f4) Tk::Entry=HASH(0xed9664) focus Tk::Entry=HASH(0xed9664) Tk::Entry=HASH(0xed9644)

    This works

    sub defineOrder { my $widget; for (my $i=0; defined( $_[$i+1] ); $i++) { $_[$i]->bind( '<Key-Return>', [\&focus, $_[$i+1]]); $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); } # Uncomment this line if you want to wrap around $_[ $#_ ]->bind('<Key-Return>', [\&focus, $_[0]]); $_[ $#_ ]->bind('<Tab>', [\&focus, $_[0]]); $_[0]->focus; }

    Using defineOrder($win, $foo,$baa,$bar,$boo,$baz); eliminates the need for the wraparound portion

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found