根据循环使用perl TK制作按钮列表

问题描述 投票:0回答:1

我在数组中的项目循环如下:

("Hugo", "Gilbert", "Linda", "Katrina")

[我想做的是设计一个perl Tk脚本,该脚本允许我基于数组中的内容创建许多单选按钮,如下所示:

<> Hugo
<> Gilbert
<> Linda
<> Katrina

当我单击雨果时,当我单击每个按钮时,我都会收到一条弹出消息,显示“您选择了雨果。”>

下面是我试图完成此操作的代码段:

#!/usr/bin/perl -w
# 
use Tk;
use strict;

my $mw = MainWindow->new;
$mw->geometry("200x500");
$mw->title("Button Test");


my @items = ("Hugo", "Gilbert", "Linda", "Katrina");

foreach my $item(@items) {
    print "$item\n";
    $mw->Radiobutton(-text => "$item", -command => \&button1_sub)->pack();
}


sub button1_sub {
  my $button=@_;
  $mw->messageBox(-message => "$button Pushed", -type => "ok");
}
MainLoop;

我无法从此代码中获得所需的结果。我如何调整代码以获得上面描述的结果?

我在数组中的项目循环看起来像这样:(“ Hugo”,“ Gilbert”,“ Linda”,“ Katrina”)我试图做的是设计一个允许我创建的perl Tk脚本许多单选按钮...

arrays loops perl button tk
1个回答
0
投票

两个问题:

© www.soinside.com 2019 - 2024. All rights reserved.