0

我有一个非常简单的 GUI,它与 postgresql 数据库交互。主机分为 4 个象限,每个象限有 4 个入口小部件。这是一个象限的示例代码

my $f_blue = $bottom_half->Frame(-bg=>'BLUE')-> pack(-side=>'left', -expand=>1, -fill=>'both');
$f_blue->Label(-text=>'BLUE', -bg=>'blue', -fg=>'white')->pack(-side=>'top');

my $blue_table = $f_blue->Table(-rows => 3,
                   -columns => 3,
                   -fixedrows => 1,
                   -fixedcolumns => 1,
                   -scrollbars => 'oo',
                   -relief => 'raised') -> pack(-side => 'top', -expand => 1, -fill=>'both');

$blue_table -> put(1,1,
          $blue_table->Label(-text => 'Cs-137:'));

my $t_blue_cs137 = $blue_table->Entry(-selectbackground=>"blueviolet");
$blue_table -> put(1,2,$t_blue_cs137);

$blue_table -> put(1,3,
          $blue_table->Label(-text => 'MBq'));



$blue_table -> put(2,1,
          $blue_table->Label(-text => 'Tc-99m:'));
my $t_blue_tc99m = $blue_table->Entry(-selectbackground=>"blueviolet");
$blue_table -> put(2,2,$t_blue_tc99m);
$blue_table -> put(2,3,
          $blue_table->Label(-text => 'MBq:'));

$blue_table -> put(3,1,
          $blue_table->Label(-text => 'Tl-201:'));
my $t_blue_tl201 = $blue_table->Entry(-selectbackground=>"blueviolet");
$blue_table -> put(3,2,$t_blue_tl201);
$blue_table -> put(3,3,
          $blue_table->Label(-text => 'MBq:'));

使用 GUI 输入数据时,我无法通过选项卡跳到下一个条目。有没有办法设置键绑定,所以我可以循环设置

`$t_blue_cs137` to be active
 PRESS TAB
`$t_blue_tc99m` NOW ACTIVE
PRESS TAB
`$t_blue_tl201` NOW ACTIVE
PRESS TAB
Do the same with the next quadrant
`$t_red_cs137`  in frame $f_red NOW ACTIVE

有没有办法在 perlTK 中做到这一点

我试过以下

$f_blue->bindtags( [ ($f_blue->bindtags)[$t_blue_cs137,$t_blue_tc99m,$t_blue_tl201] ] );
# fix the bindtags order so that widget events are
# processed before class events
$f_blue->bind("<Tab>", sub { $f_blue->focusNext; Tk->break; });

但是,这只能让我在每个子框架和 GUI 中的按钮之间切换

4

1 回答 1

2

定义

-takefocus => 0,

Table配置中。

默认情况下,-takefocus设置为 true 值,这导致该FocusChildren方法返回一个空列表,这反过来意味着永远不会将焦点赋予表的子小部件。不是最好的默认值,但这种行为是在 Tk 402.001 中引入的,现在可能为时已晚,无法更改。但也许文档中应该有一段描述这个陷阱......

于 2013-11-14T20:58:59.583 回答