<?xml version="1.0" encoding="windows-1252"?>
<node id="201500" title="Tk Defining focus order for Return Key" created="2002-09-28 18:40:04" updated="2005-08-12 17:38:24">
<type id="1980">
snippet</type>
<author id="178658">
hiseldl</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
&lt;P&gt;Tk allows 'tab-key' ordering by the order in which you pack your widgets.  One way to change this behaviour is to bind a key event to the focus method of the 'next' widget in line.&lt;/P&gt;
&lt;P&gt;In this snippet, I bound the return key to the next 'Entry' widget in line.  Uncomment the line noted in the code if you want to wrap around.&lt;/P&gt;
&lt;P&gt;--&lt;br/&gt;[hiseldl]&lt;br/&gt;What time is it? It's [190308|Camel Time!]&lt;P&gt;
</field>
<field name="snippetcode">
&lt;CODE&gt;use Tk;
use strict;
use warnings;

my $win = MainWindow-&gt;new();
$win-&gt;Button(-text=&gt;'Other Window',-command=&gt;\&amp;otherwindow)-&gt;pack;
sub otherwindow
{
    my $otherwin = $win-&gt;Toplevel;
    my $foo = $otherwin-&gt;Entry-&gt;pack;
    my $bar = $otherwin-&gt;Entry-&gt;pack;
    my $baz = $otherwin-&gt;Entry-&gt;pack;

    &amp;defineOrder($foo, $bar, $baz);
}    

sub defineOrder
{
    my $widget;
    for (my $i=0; defined( $_[$i+1] ); $i++)
    {
        $_[$i]-&gt;bind('&lt;Key-Return&gt;', [\&amp;focus, $_[$i+1]]);
    }

    # Uncomment this line if you want to wrap around
    #$_[$#_]-&gt;bind('&lt;Key-Return&gt;',  [\&amp;focus, $_[0]]);

    $_[0]-&gt;focus;
}

sub focus
{
    my ($tk, $self) = @_;
    $self-&gt;focus;
}

MainLoop();
&lt;/CODE&gt;</field>
</data>
</node>
