michael99 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Tk module to create a simple GUI. I would like to get the "Save and exit" button to be located at most bottom position in the GUI. When running my code below, the button is somewhere in the middle of the GUI. I have tried with -side option.

use Tk; my $mw = MainWindow->new(-title => 'IP User config form'); my $label2 = $mw->Label(-text => 'Part 1: Mandotory fields filling'); $label2->pack(); my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); my $f2 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); $f1->Label(-text => 'Config ID')->grid($f1->Entry(-textvariable => \$d +ss_config_id), $f1->Label(-text => 'Milestone ID'), $f1->Entry(-textvariable => \$milestone_id), -sticky => 'w', -padx => +2, -pady => 5); $f1->Label(-text => 'IPX_FQN')->grid($f1->Entry(-textvariable => \$ipx +_fqn), $f1->Label(-text => 'IPX NEWLINE'), $f1->Entry(-textvariable => \$ipx_new_line), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'IPX consumer groups')->grid($f1->Entry(-textvaria +ble => \$ipx_consumer_grp), $f1->Label(-text => 'IPP Tag'), $f1->Entry(-textvariable => \$ipp_tag), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'Process')->grid($f1->Entry(-textvariable => \$pro +cess), $f1->Label(-text => 'Runset version'), $f1->Entry(-textvariable => \$runset_ver), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'UPF version')->grid($f1->Entry(-textvariable => \ +$upf_ver), $f1->Label(-text => 'Contact (username:contact_type)'), $f1->Entry(-textvariable => \$contact), -sticky => 'w', -padx => 2, -pady => 5); #my $label3 = $mw->Label(-text => 'Release Notes Enabling', -relief=>' +groove')->pack(-fill => 'x', -side => 'bottom'); my $label3 = $mw->Label(-text => 'Release notes'); $label3->pack(); my $values2; my @chk_boxes2 = ( [\$values2->{notes},'Notes'], [\$values2->{issues},'Issues'], [\$values2->{comments},'Comments'], [\$values2->{changes},'Changes'], ); check_box2(\@chk_boxes2); $f2->pack(); my $button = $mw->Button(-text => "Save and exit", -command => \&reFor +m)->grid('-', '-', '-', -pady => 10)->pack(-side=>'bottom'); $f2->pack(); MainLoop; sub check_box2 { my $data = shift; my $index = 0; for my $chk_box ( @{$data} ) { my $column = $index % 2; my $row = int($index/2); my $chk_x = $f2->Checkbutton( -text => $chk_box->[1], -variable => $chk_box->[0] )->grid( -column => $column, -row => $row, -sticky + => 'w'); #$chk_x->select if $index == 0; $index++; } my $chk_x=$f2->pack(-side=>'bottom'); }

Replies are listed 'Best First'.
Re: Perl tk module
by tybalt89 (Monsignor) on May 27, 2020 at 14:13 UTC
    #!/usr/bin/perl #use strict; # https://perlmonks.org/?node_id=11117336 #use warnings; use Tk; my $mw = MainWindow->new(-title => 'IP User config form'); my $label2 = $mw->Label(-text => 'Part 1: Mandotory fields filling'); $label2->pack(); my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); my $f2 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); $f1->Label(-text => 'Config ID')->grid($f1->Entry(-textvariable => \$d +ss_config_id), $f1->Label(-text => 'Milestone ID'), $f1->Entry(-textvariable => \$milestone_id), -sticky => 'w', -padx => +2, -pady => 5); $f1->Label(-text => 'IPX_FQN')->grid($f1->Entry(-textvariable => \$ipx +_fqn), $f1->Label(-text => 'IPX NEWLINE'), $f1->Entry(-textvariable => \$ipx_new_line), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'IPX consumer groups')->grid($f1->Entry(-textvaria +ble => \$ipx_consumer_grp), $f1->Label(-text => 'IPP Tag'), $f1->Entry(-textvariable => \$ipp_tag), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'Process')->grid($f1->Entry(-textvariable => \$pro +cess), $f1->Label(-text => 'Runset version'), $f1->Entry(-textvariable => \$runset_ver), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'UPF version')->grid($f1->Entry(-textvariable => \ +$upf_ver), $f1->Label(-text => 'Contact (username:contact_type)'), $f1->Entry(-textvariable => \$contact), -sticky => 'w', -padx => 2, -pady => 5); #my $label3 = $mw->Label(-text => 'Release Notes Enabling', -relief=>' +groove')->pack(-fill => 'x', -side => 'bottom'); my $label3 = $mw->Label(-text => 'Release notes'); $label3->pack(); my $values2; my @chk_boxes2 = ( [\$values2->{notes},'Notes'], [\$values2->{issues},'Issues'], [\$values2->{comments},'Comments'], [\$values2->{changes},'Changes'], ); check_box2(\@chk_boxes2); $f2->pack(); #my $button = $mw->Button(-text => "Save and exit", -command => \&reFo +rm)->grid('-', '-', '-', -pady => 10)->pack(-side=>'bottom'); # BUG H +ERE my $button = $mw->Button(-text => "Save and exit", -command => \&reFor +m)->pack(-side=>'bottom'); $f2->pack(); MainLoop; sub check_box2 { my $data = shift; my $index = 0; for my $chk_box ( @{$data} ) { my $column = $index % 2; my $row = int($index/2); my $chk_x = $f2->Checkbutton( -text => $chk_box->[1], -variable => $chk_box->[0] )->grid( -column => $column, -row => $row, -sticky = +> 'w'); #$chk_x->select if $index == 0; $index++; } #my $chk_x=$f2->pack(-side=>'bottom'); # AND HERE my $chk_x=$f2->pack(-side=>'top'); }
      Thank you for your reply. By using your modified code, the "Release notes" header is after the checkbox section. I would like to have the order: Release notes header --> Checkbox --> "save and exit" button. Thanks
        #!/usr/bin/perl #use strict; # https://perlmonks.org/?node_id=11117336 #use warnings; use Tk; my $mw = MainWindow->new(-title => 'IP User config form'); my $label2 = $mw->Label(-text => 'Part 1: Mandotory fields filling'); $label2->pack(); my $f1 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); my $label3 = $mw->Label(-text => 'Release notes'); $label3->pack(); my $f2 = $mw->Frame(-borderwidth => 2, -relief => 'groove', -width => +30) ->pack(-side => 'top', -fill => 'both', -expand => 1); $f1->Label(-text => 'Config ID')->grid($f1->Entry(-textvariable => \$d +ss_config_id), $f1->Label(-text => 'Milestone ID'), $f1->Entry(-textvariable => \$milestone_id), -sticky => 'w', -padx => +2, -pady => 5); $f1->Label(-text => 'IPX_FQN')->grid($f1->Entry(-textvariable => \$ipx +_fqn), $f1->Label(-text => 'IPX NEWLINE'), $f1->Entry(-textvariable => \$ipx_new_line), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'IPX consumer groups')->grid($f1->Entry(-textvaria +ble => \$ipx_consumer_grp), $f1->Label(-text => 'IPP Tag'), $f1->Entry(-textvariable => \$ipp_tag), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'Process')->grid($f1->Entry(-textvariable => \$pro +cess), $f1->Label(-text => 'Runset version'), $f1->Entry(-textvariable => \$runset_ver), -sticky => 'w', -padx => 2, -pady => 5); $f1->Label(-text => 'UPF version')->grid($f1->Entry(-textvariable => \ +$upf_ver), $f1->Label(-text => 'Contact (username:contact_type)'), $f1->Entry(-textvariable => \$contact), -sticky => 'w', -padx => 2, -pady => 5); #my $label3 = $mw->Label(-text => 'Release Notes Enabling', -relief=>' +groove')->pack(-fill => 'x', -side => 'bottom'); my $values2; my @chk_boxes2 = ( [\$values2->{notes},'Notes'], [\$values2->{issues},'Issues'], [\$values2->{comments},'Comments'], [\$values2->{changes},'Changes'], ); check_box2(\@chk_boxes2); $f2->pack(); #my $button = $mw->Button(-text => "Save and exit", -command => \&reFo +rm)->grid('-', '-', '-', -pady => 10)->pack(-side=>'bottom'); # BUG H +ERE my $button = $mw->Button(-text => "Save and exit", -command => \&reFor +m)->pack(-side=>'bottom'); $f2->pack(); MainLoop; sub check_box2 { my $data = shift; my $index = 0; for my $chk_box ( @{$data} ) { my $column = $index % 2; my $row = int($index/2); my $chk_x = $f2->Checkbutton( -text => $chk_box->[1], -variable => $chk_box->[0] )->grid( -column => $column, -row => $row, -sticky = +> 'w'); #$chk_x->select if $index == 0; $index++; } #my $chk_x=$f2->pack(-side=>'bottom'); # AND HERE my $chk_x=$f2->pack(-side=>'top'); }
Re: Perl tk module
by Anonymous Monk on May 28, 2020 at 02:33 UTC