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();
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|