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

tab x 5, enter x 10

#!/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(qw' -text $foo ')->pack; my $bar = $win->Entry(qw' -text $bar ')->pack; my $baz = $win->Entry(qw' -text $baz ')->pack; my $boo = $win->Entry(qw' -text $boo ')->pack; my $baa = $win->Entry(qw' -text $baa ')->pack; &defineOrder($foo,$baa,$bar,$boo,$baz); DumpBindtags($win, $foo,$baa,$bar,$boo,$baz); print " $win = \$win $foo = \$foo $bar = \$bar $baz = \$baz $boo = \$boo $baa = \$baa "; sub DumpBindtags { for my $o ( @_ ) { print "$o bindtags ( ", join ' , ' , $o->bindtags, " )\n"; } } 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]]); #~ $_[$i]->bind( '<Tab>', [\&focus, $_[$i+1]]); ## in order tra +versal } # Uncomment this line if you want to wrap around $_[$#_]->bind('<Key-Return>', [\&focus, $_[0]]); $_[0]->focus; } sub focus { warn "focus @_\n"; my ($tk, $self) = @_; $self->focus; Tk::break(); } MainLoop(); __END__
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


In reply to Re^2: Tab Order for Widgets in HList by Anonymous Monk
in thread Tab Order for Widgets in HList by kean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.