Hi monks,
I want to print the options selected by the user in the text box after the push button is pressed. Default options for the option menu needs to be none and the default option for the entry menu needs to be " ". I am not sure how to set the default option. Once the user selects a new option and presses Go! button I want those values to be retrieved and printed inside the push button function. I am not sure how to print the values that are got by selecting from the optionsmenu.
So the two major questions are
1. How to set a default value to the options menus and the entry menus.
2. How to get the value from the options menu once push button is pressed and print it in the text box.
Kindly let me know how to modify my code :)
use Tk;
use Tk::widgets qw(LabFrame);
use File::Spec::Functions qw(canonpath);
use Tk::Optionmenu;
my $mw = MainWindow->new;
#Entering the metal stack options and metal lines
my $metaloption_lf2 = $mw->LabFrame(
# -label => 'XY Co-Ordinates and Metal to trace',
# -labelside => 'acrosstop',
# -foreground => 'blue',
);
$metaloption_lf2->pack(
-expand => 0,
-fill => 'x',
);
my $frm_metalOption2 =$metaloption_lf2 ->Frame()->pack; # just for cen
+tering the buuton row
##########################################Co-ordinate and metal option
+: Row 2 ####################################################
my $labx2 = $metaloption_lf2 -> Label(-text=>"X2:")-> grid(-row=>1,-co
+lumn=>0)->pack( -side => 'left' );
my $x2 = $metaloption_lf2->Entry(
-width => 15,
)->grid(
-row => 1, -column => 1,
-padx => 5,
-pady => 5,
)->pack( -side => 'left' );
my $laby2 = $metaloption_lf2 -> Label(-text=>"Y2:")-> grid(-row=>1,-co
+lumn=>2)->pack( -side => 'left' );
my $y2 = $metaloption_lf2->Entry(
-width => 15,
)->grid(
-row => 1, -column => 3,
-padx => 5,
-pady => 5,
)->pack( -side => 'left' );
my $labmetal2 = $metaloption_lf2 -> Label(-text=>"Metal:")-> grid(-row
+=>1,-column=>4)->pack( -side => 'left' );
my $opt2 = $metaloption_lf2->Optionmenu(
-options => [[M1=>1], [M2=>2], [M3=>3], [M4=>4]],
#-command => sub { print "got: ", shift, "\n" },
#-command => sub { get() },
-variable => \$var,
-textvariable => \$tvar
)->pack(-side => 'left', -anchor => 'n',);
# populate with some values unless done during initialisation
$opt2->addOptions([M5=>5],[M6=>6],[M7=>7],[M8=>8],[M9=>9],[M10=>10], [
+NONE=>" "]);
$tvar = $default_var; #set default
$opt2-> configure( -textvariable => \$tvar );
######################################################################
+############################################################
#Entering the metal stack options and metal lines
my $metaloption_lf3 = $mw->LabFrame(
# -label => 'XY Co-Ordinates and Metal to trace',
# -labelside => 'acrosstop',
# -foreground => 'blue',
);
$metaloption_lf3->pack(
-expand => 0,
-fill => 'x',
);
my $frm_metalOption3 =$metaloption_lf3 ->Frame()->pack; # just for cen
+tering the buuton row
##########################################Co-ordinate and metal option
+: Row 3 ####################################################
my $labx3 = $metaloption_lf3 -> Label(-text=>"x3:")-> grid(-row=>1,-co
+lumn=>0)->pack( -side => 'left' );
my $x3 = $metaloption_lf3->Entry(
-width => 15,
)->grid(
-row => 1, -column => 1,
-padx => 5,
-pady => 5,
)->pack( -side => 'left' );
my $laby3 = $metaloption_lf3 -> Label(-text=>"y3:")-> grid(-row=>1,-co
+lumn=>2)->pack( -side => 'left' );
my $y3 = $metaloption_lf3->Entry(
-width => 15,
)->grid(
-row => 1, -column => 3,
-padx => 5,
-pady => 5,
)->pack( -side => 'left' );
my $labmetal3 = $metaloption_lf3 -> Label(-text=>"Metal:")-> grid(-row
+=>1,-column=>4)->pack( -side => 'left' );
my $opt3 = $metaloption_lf3->Optionmenu(
-options => [[M1=>1], [M2=>2], [M3=>3], [M4=>4]],
#-command => sub { print "got: ", shift, "\n" },
#-command => sub { get() },
-variable => \$var,
-textvariable => \$tvar
)->pack(-side => 'left', -anchor => 'n',);
# populate with some values unless done during initialisation
$opt3->addOptions([M5=>5],[M6=>6],[M7=>7],[M8=>8],[M9=>9],[M10=>10], [
+NONE=>" "]);
$tvar = $default_var; #set default
$opt3-> configure( -textvariable => \$tvar );
######################################################################
+############################################################
#Running the file
my $run_lf = $mw->LabFrame(
-label => 'Run',
-labelside => 'acrosstop',
-foreground => 'blue',
);
$run_lf->pack(
-expand => 1,
-fill => 'both',
);
my $but = $run_lf->Button(
-text => "Go!",
-command => \&push_button,
)->pack;
#Text Box
my $txt = $run_lf->Scrolled(
'Text',
-width => 40,
-height => 15,
-wrap => 'word',
-scrollbars => 'e',
-background => 'white',
);
$txt->pack(
-expand => 1,
-fill => 'both',
-padx => 5,
-pady => 5,
);
MainLoop;
#SUB PROCEDURES
sub push_button {
$xcord2 = $x2->get();
$xcord3 = $x3->get();
$ycord2 = $y2->get();
$ycord3 = $y3->get();
$metalSelection2 = $opt2->get($var);
$metalSelection3 = $opt3->get($var);
$gdsname ||= '?';
$txt->insert( 'end', "Execution in progress\n" );
#$txt->update();
$txt->insert( 'end', "Operation is successful. Second co-ordinate deta
+ils $xcord2 $ycord2 are co-ordinates. $metalSelection2 is selected. \
+n Third co-ordinate details $xcord3 $ycord3 are co-ordinates. $metalS
+election3 is selected..\n" );
}
The text box should be able to print which are the co-ordinates and the metal options (M1, M2 e.t.c) selected by the user
please let me know how I should modify my code to achieve this
thanks,