Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Tk Defining focus order for Return Key

by hiseldl (Priest)
on Sep 28, 2002 at 22:40 UTC ( #201500=snippet: print w/ replies, xml ) Need Help??

Description:

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.

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.

--
hiseldl
What time is it? It's Camel Time!

use Tk;
use strict;
use warnings;

my $win = MainWindow->new();
$win->Button(-text=>'Other Window',-command=>\&otherwindow)->pack;
sub otherwindow
{
    my $otherwin = $win->Toplevel;
    my $foo = $otherwin->Entry->pack;
    my $bar = $otherwin->Entry->pack;
    my $baz = $otherwin->Entry->pack;

    &defineOrder($foo, $bar, $baz);
}    

sub defineOrder
{
    my $widget;
    for (my $i=0; defined( $_[$i+1] ); $i++)
    {
        $_[$i]->bind('<Key-Return>', [\&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();
Comment on Tk Defining focus order for Return Key
Download Code

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-09-19 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (145 votes), past polls