原文:
10.14. How do I group Radiobuttons together?
Specify the -variable option on each one. Here is an example pulled from the icon.pl demo script: $letters = ''; my $w_frame_left_b3 = $w_frame_left->Radiobutton( -bitmap => "\@$tk_library/demos/images/letters", -variable => \$letters, -value => 'full', ); my $w_frame_left_b4 = $w_frame_left->Radiobutton( -bitmap => "\@$tk_library/demos/images/noletters", -variable => \$letters, -value => 'empty', );
译文:
10.14. 如何将多个单选按钮(radiobutton)组合在一起?
答案是:给每一个单选按钮设置-variable选项。
下面是一个从icon.pl演示脚本中摘录下来的例子:
my $letters = '';
@pl = qw/-side top -expand yes/;
my $frame_left_b3 = $frame_left->Radiobutton(
-bitmap => '@' . Tk->findINC('demos/images/letters'),
-variable => \$letters,
-value => 'full',
);
$frame_left_b3->pack(@pl);
my $frame_left_b4 = $frame_left->Radiobutton(
-bitmap => '@' . Tk->findINC('demos/images/noletters'),
-variable => \$letters,
-value => 'empty',
);
(译者注:如果你已经安装了Perl/Tk,完整的演示脚本可以在Tk安装目录——$Tk::library——中的demos/widget_lib中找到。要想知道它的运行结果,可以直接运行widget,这就是其中的第一部分“Labels, buttons, checkbuttons, and radiobuttons”的第6个例子。另外,如果你对checkbutton和radiobutton还不是太清楚,建议先看一下前面的例子3和 4。)