I'm trying to left align 4 sets of checkboxes in Tk. I have extracted the part of my program that builds the checkboxes. I am packing them to the left and anchoring them west, but the checkboxes are anything but aligned. I tried creating a frame for each of the 4 sets of checkboxes, but that did not help. Please note that I am building the sets of checkboxes from the bottom of the screen up, which should not matter as far as alignment goes. I'm sure that I'm missing somehting very simple here. How can I get the checkboxes to align regardless of the text that follows them? Thanks.

#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry("360x250+280+60"); $mw->bind('<Escape>' => sub {exit;}); $mw->configure(-title => 'Test Checkbox Alignment'); my ($qv, $dg, $yb, $pv, $rd, $oc, $hr, $tm); ################################################################### # Create frame for 4th set of check boxes. ################################################################### my $frame_cb0 = $mw->Frame; $frame_cb0->pack(-side => "bottom", -pady => 1); ################################################################### # Create first check box for 4th set. ################################################################### my $qv_cbox = $frame_cb0->Checkbutton( -text => 'QuickCheck', -variable => \$qv, ); $qv_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create second check box for 4th set. ################################################################### my $dg_cbox = $frame_cb0->Checkbutton( -text => 'Systems Guide', -variable => \$dg, ); $dg_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create frame for 3rd set of check boxes. ################################################################### my $frame_cb1 = $mw->Frame; $frame_cb1->pack(-side => "bottom", -pady => 1); ################################################################### # Create first check box for 3rd set. ################################################################### my $yb_cbox = $frame_cb1->Checkbutton( -text => 'Study', -variable => \$yb, ); $yb_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create second check box for 3rd set. ################################################################### my $pv_cbox = $frame_cb1->Checkbutton( -text => 'Analyze', -variable => \$pv, ); $pv_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create frame for 2nd set of check boxes. ################################################################### my $frame_cb2 = $mw->Frame; $frame_cb2->pack(-side => "bottom", -pady => 1); ################################################################### # Create first check box for 2nd set. ################################################################### my $rd_cbox = $frame_cb2->Checkbutton( -text => 'Read', -variable => \$rd, ); $rd_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create second check box for 2nd set. ################################################################### my $oc_cbox = $frame_cb2->Checkbutton( -text => 'Configure', -variable => \$oc, ); $oc_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create frame for 1st set of check boxes. ################################################################### my $frame_cb3 = $mw->Frame; $frame_cb3->pack(-side => "bottom", -pady => 1); ################################################################### # Create first check box for 1st set. ################################################################### my $hr_cbox = $frame_cb3->Checkbutton( -text => 'Troubleshoot', -variable => \$hr, ); $hr_cbox->pack( -side => "left", -anchor => 'w', ); ################################################################### # Create second check box for 1st set. ################################################################### my $tm_cbox = $frame_cb3->Checkbutton( -text => 'Prioritize', -variable => \$tm, ); $tm_cbox->pack( -side => "left", -anchor => 'w', ); MainLoop; exit;

"Its not how hard you work, its how much you get done."


In reply to Aligning Tk Checkboxes by roho

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.