2015-11-29 57 views
0

我是perl tk的新手,我被困在一個問題上。我試圖通過函數中的 -變量字段。在一個下拉我有 -variable => \$fever ,我也有-command => [\&show_choice, \$fever] ..我試圖打印下拉選項選擇的值。但是我得到的是像SCALAR(0X765 ...)。我如何獲得顯示值?我嘗試使用-textVariable而不是變量,但它的工作方式相同。在Perl中傳遞函數的參數tk

下面是代碼:

#!/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; 

回答

0

SCALAR(0X765...)輸出表示爲標量,而不是一個簡單的標量的參考。我想你想直接通過$fever到你的命令,而不是參考\$fever

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

如果我這樣做,我會在串聯(。)或字符串中使用未初始化值$ _ [0]。我在問題中添加我的代碼以使其更清楚。 –