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

oh great Monks of wisdom, is there one of you who could direct this weary traveler with left aligning checkbuttons.

after an hour of messing around with -side =>, and anchor => I seem to be going around in circles. please oh please provide me with your guidance.

below you will find my humble work.
#!/usr/local/bin/perl use Tk; use strict; use warnings; # Main Window my $mw = new MainWindow; #GUI Building Area my @style_sizes_array = qw(XXS XS S M L XL XXL XXXL); #checkbutton sizes setup for (my $ctr = 0; $ctr < @style_sizes_array; $ctr++){ my $size_type = $style_sizes_array[$ctr]; my $frmTemp = $mw->Frame() ->pack(-anchor => 'nw',-side => 'top'); $frmTemp ->Checkbutton(-text => $size_type,-width => 10, -variable => \$ctr)->pack(-anchor =>'nw',-fi +ll => 'both',-expand => 1); } MainLoop();

Replies are listed 'Best First'.
Re: checkbutton alignment
by Marshall (Canon) on Nov 11, 2011 at 22:38 UTC
    Is this more what you are looking for? I made a single frame for all the buttons, then when buttons are created within that frame, pack them as anchored to the west. The default packing will cause them to be put one on top of another (vertically). Update: don't need -side, just -anchor=>'w' for each button's pack
    use Tk; use strict; use warnings; # Main Window my $mw = new MainWindow; #GUI Building Area my @style_sizes_array = qw(XXS XS S M L XL XXL XXXL); my $buttonFrame = $mw->Frame()->pack(); #checkbutton sizes setup for (my $ctr = 0; $ctr < @style_sizes_array; $ctr++){ my $size_type = $style_sizes_array[$ctr]; $buttonFrame ->Checkbutton(-text => $size_type, -padx=>20, -variable => \$ctr)->pack(-anchor=>'w'); } MainLoop();
      Marshall, thanks for the quick reply you have saved my sanity this night. This is for a much bigger program, I think I have had one of those 'not being able to see the trees because of the forest' days.

      Thanks Again.
Re: checkbutton alignment
by zentara (Cardinal) on Nov 12, 2011 at 11:36 UTC
    There seems to be an interaction between the Frame and the Checkbuttons. If you pack your Checkbuttons in the $mw, the -anchor=>'w' holds position, on a window resize. But if you add a Frame, and put the Checkbuttons in that Frame, the -anchor=>'w' dosn't hold the Checkbuttons, unless the Frame is packed with (-expand=>1, -fill=>'both').

    Try resizing the $mw in this script with and without the Frame->pack(-expand=>1, -fill=>'both')

    #!/usr/bin/perl use Tk; use strict; use warnings; # Main Window my $mw = new MainWindow; #GUI Building Area my @style_sizes_array = qw(XXS XS S M L XL XXL XXXL); # Checkbuttons won't hold left this way #my $buttonFrame = $mw->Frame()->pack(); # works my $buttonFrame = $mw->Frame()->pack(-expand=>1, -fill=>'both'); #checkbutton sizes setup for (my $ctr = 0; $ctr < @style_sizes_array; $ctr++){ my $size_type = $style_sizes_array[$ctr]; $buttonFrame ->Checkbutton(-text => $size_type, -padx=>20, -variable => \$ctr)->pack(-anchor=>'w'); } MainLoop();

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh