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

I'm having trouble with a TK frame with radio buttons. I'd like each row in my list of radio buttons aligned with the left side of the frame; the code below renders each button row centered. The result looks ragged and goofy. Can anyone assist? Many many thanks. water
my $left_frame = $main->Frame; my $quit_button = $left_frame->Button( -text => 'quit', -command => [ $main => 'destroy' ] ); $quit_button->pack( side => 'top' ); foreach my $r (@radio_values) { $left_frame->Radiobutton( -text => $r, -variable => \$radio_state, -value => $r, -command => [ sub { 'foo' } ], -anchor =>'e', , )->pack( side => 'top', ); }

Replies are listed 'Best First'.
Re: Beginner TK frame question: left aligning buttons
by tachyon (Chancellor) on Sep 11, 2004 at 11:54 UTC

    This is left justified, vertically aligned ie the usual. You need the west anchor and a width to make it take. pack( side => 'top' ) is the default so just ->pack() will do, or even just ->pack

    $left_frame->Radiobutton( -text => $r, -variable => \$radio_state, -value => $r, -command => [ sub { 'foo' } ], -anchor => 'w', -width => 10, )->pack( side => 'top', );

    cheers

    tachyon

      Instead of hard-coding a width, you can also use the
      -fill => 'x'
      option of pack() to make the widget take any extra horizontal space in its parent. You still need the
      -anchor => 'w'
      bit of course.

        That is much more elegant.

        cheers

        tachyon