在Perl tk中将参数传递给函数

在Perl tk中将参数传递给函数,perl,tk,Perl,Tk,我是perl-tk新手,遇到了一个问题。我想通过考试 -函数中的变量字段。在一个下拉列表中,我 -变量=>\$fever 我还有-command=>[\&show\u选项,\$fever]。。我正在尝试打印所选下拉选项的值。但我得到的是标量(0X765…)。如何获取显示的值?我试着用-textVariable代替variable,但效果是一样的 代码如下: #!/usr/bin/perl use Data::Printer; use warnings; use Tk; my $mw = Mai

我是perl-tk新手,遇到了一个问题。我想通过考试 -函数中的变量字段。在一个下拉列表中,我
-变量=>\$fever
我还有
-command=>[\&show\u选项,\$fever]
。。我正在尝试打印所选下拉选项的值。但我得到的是标量(0X765…)。如何获取显示的值?我试着用-textVariable代替variable,但效果是一样的

代码如下:

#!/usr/bin/perl
use Data::Printer;
use warnings;
use Tk;

my $mw = MainWindow->new;
$mw->geometry("700x700");
$mw->title("AIR (Auto Immune Research)");

#create own title font
$mw->fontCreate("sectionTitleFont", -family => "Helvetica", -size => 36, -weight => "bold");

my $symptomFrame = $mw->Frame(-background => 'white', -foreground => 'black')->pack(-side => "top", -fill => "x");
my $pathologyFrame = $mw->Frame(-background => 'white', -foreground => 'black')->pack(-side => "bottom", -fill => "x");

my $symptomLabel = $symptomFrame->Label(-background => 'white', -text => 'Patient Symptoms', -font => 'sectionTitleFont');
my $pathologyLabel = $pathologyFrame->Label(-background => 'white', -text => 'Pathological Findings', -font => 'sectionTitleFont');

my $severityText = $symptomFrame->Label(-background => 'white', -text => 'Intensity');

#cough
my $coughCheckBox = $symptomFrame->Checkbutton(-text => 'Cough', -background => 'white', -variable => \$couchCheck);
my $coughSeverity;
my $coughSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$coughSeverity,
-command => [\&show_choice, $coughSeverity, "cough", \$couchCheck]
);

#Fever
my $feverCheckBox = $symptomFrame->Checkbutton(-text => 'Fever', -background => 'white', -variable => \$feverCheck);
my $feverSeverity;
my $feverSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$feverSeverity,
-command => [\&show_choice, $feverSeverity, "fever", \$feverCheck]
);

#joint pain
my $jointPainCheckBox = $symptomFrame->Checkbutton(-text => 'Joint Pain', -background => 'white', -variable => \$jointPainCheck);
my $jointPainSeverity;
my $jointPainSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$jointPainSeverity,
-command => [\&show_choice, $jointPainSeverity, "joint pain", \$jointPainCheck]
);

#Moon face
my $moonFaceCheckBox = $symptomFrame->Checkbutton(-text => 'Moon Face', -background => 'white', -variable => \$moonFaceCheck);
my $moonFaceSeverity;
my $moonFaceSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$moonFaceSeverity,
-command => [\&show_choice, $moonFaceSeverity, "moon face", \$moonFaceCheck]
);

#fatigue
my $fatigueBox = $symptomFrame->Checkbutton(-text => 'Fatigue', -background => 'white', -variable => \$fatigueCheck);
my $fatigueSeverity;
my $fatigueSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$fatigueSeverity,
-command => [\&show_choice, $fatigueSeverity, "fatigue", \$fatigueCheck]
);

#Skin Redness
my $skinRednessBox = $symptomFrame->Checkbutton(-text => 'Skin Redness', -background => 'white', -variable => \$skinRednessCheck);
my $skinRednessSeverity;
my $skinRednessSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$skinRednessSeverity,
-command => [\&show_choice, $skinRednessSeverity, "skin redness", \$skinRednessCheck]
);

#Drowsiness
my $drowsinessBox = $symptomFrame->Checkbutton(-text => 'Drowsiness', -background => 'white', -variable => \$drowsinessCheck);
my $drowsinessSeverity;
my $drowsinessSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$drowsinessSeverity,
-command => [\&show_choice, $drowsinessSeverity, "drowsiness", \$drowsinessCheck]
);

#Headache
my $headacheBox = $symptomFrame->Checkbutton(-text => 'Headache', -background => 'white', -variable => \$headacheCheck);
my $headacheSeverity;
my $headacheSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$headacheSeverity,
-command => [\&show_choice, $headacheSeverity, "headache", \$headacheCheck]
);


#Inflamations
my $inflamationsBox = $symptomFrame->Checkbutton(-text => 'Inflamations', -background => 'white', -variable => \$inflamationsCheck);
my $inflamationsSeverity;
my $inflamationsSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$inflamationsSeverity,
-command => [\&show_choice, $inflamationsSeverity, "inflamations", \$inflamationsCheck]
);

#Itchiness
my $itchinessBox = $symptomFrame->Checkbutton(-text => 'Itchiness', -background => 'white', -variable => \$itchinessCheck);
my $itchinessSeverity;
my $itchinessSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$itchinessSeverity,
-command => [\&show_choice, $itchinessSeverity, "itchiness", \$itchinessCheck]
);

#Blood in Urine
my $bloodBox = $symptomFrame->Checkbutton(-text => 'Blood in Urine', -background => 'white', -variable => \$bloodCheck);
my $bloodSeverity;
my $bloodSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$bloodSeverity,
-command => [\&show_choice, $bloodSeverity, "blood in urine", \$bloodCheck]
);

#Depression
my $depressionBox = $symptomFrame->Checkbutton(-text => 'Depression', -background => 'white', -variable => \$depressionCheck);
my $depressionSeverity;
my $depressionSeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$depressionSeverity,
-command => [\&show_choice, $depressionSeverity, "depression", \$depressionCheck]
);

#Sleep Deprevity
my $sleepDeprevityBox = $symptomFrame->Checkbutton(-text => 'Sleep Deprevity', -background => 'white', -variable => \$sleepCheck);
my $sleepDeprevitySeverity;
my $sleepDeprevitySeverityDD = $symptomFrame->Optionmenu(
-options => [[1=>1], [2=>2], [3=>3], [4=>4], [5=>5], [6=>6], [7=>7], [8=>8], [9=>9], [10=>10]],
-variable => \$sleepDeprevitySeverity,
-command => [\&show_choice, $sleepDeprevitySeverity, "sleep deprevity", \$sleepCheck]
);


#emty label to give empty space
my $emptyLabel = $symptomFrame->Label(-background => 'white', -width => '20');
$symptomLabel->grid(-columnspan => '5');
$pathologyLabel->grid(-columnspan => '5');
#$severityText->grid;
$coughCheckBox -> grid($severityText, $coughSeverityDD, $emptyLabel, $feverCheckBox, $severityText, $feverSeverityDD);
$sleepDeprevityBox -> grid($severityText, $sleepDeprevitySeverityDD, $emptyLabel, $depressionBox, $severityText, $depressionSeverityDD);
$moonFaceCheckBox -> grid($severityText, $jointPainSeverityDD, $emptyLabel, $bloodBox, $severityText, $bloodSeverityDD);
$itchinessBox -> grid($severityText, $itchinessSeverityDD, $emptyLabel, $inflamationsBox, $severityText, $inflamationsSeverityDD);
$headacheBox -> grid($severityText, $headacheSeverityDD, $emptyLabel, $drowsinessBox, $severityText, $drowsinessSeverityDD);
$skinRednessBox -> grid($severityText, $skinRednessSeverityDD, $emptyLabel, $fatigueBox, $severityText, $fatigueSeverityDD);

sub show_choice
{
    #my $severity_value = p($_[0]);
    #$severity_value =~ s/.*\W(\w)/$1/;
    #p($severity_value);
    #my $symptom = $_[1];
    #my $checkVal = p($_[2]);
    #$checkVal =~ s/.*\W(\w)/$1/;
    #print "$severity_value \n";
    my $val = $_[0];
    print "$val \n";
    return;
}


#$fatigueBox -> grid($fatigueSeverityDD, $emptyLabel, $itchinessBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);
#$moonFaceCheckBox -> grid($jointPainSeverityDD, $emptyLabel, $bloodCheckBox, $dd3);

MainLoop;
标量(0X765…
的输出表示对标量而不是简单标量的引用。我认为您希望将
\$fever
直接传递给您的命令,而不是引用
\$fever

-command => [ \&show_choice, $fever ]

如果我这样做,我会在串联(.)或字符串中使用未初始化的值$U0。我在问题中添加了我的代码,以使其更清楚。