http://www.perlmonks.org?node_id=1093187


in reply to Re^4: How do I space out each radio button horizontally in Perl/Tk
in thread How do I space out each radio button horizontally in Perl/Tk

That's not a problem:

use strict; use warnings; use Tk; my $mw = MainWindow->new; my $package = 'normal'; foreach my $type (qw(normal pckg_A pckg_B)) { $mw->Radiobutton( -text => " $type", -value => $type, -variable => \$package, )->pack; } MainLoop;
  • Comment on Re^5: How do I space out each radio button horizontally in Perl/Tk
  • Download Code

Replies are listed 'Best First'.
Re^6: How do I space out each radio button horizontally in Perl/Tk
by Janish (Sexton) on Jul 11, 2014 at 07:02 UTC

    Thanks stefbv. However, I'm using notebook and I have it packed earlier on my code, guess I can only use grid to set the position right?

    I have something like this is my early code

    my $tab = $notebook->add('page1', -label=> 'Package'); my $mwt_pckg = $tab1->Frame()->pack ;

    Then folowing by this

    my $package = 'normal'; foreach my $type (qw(normal pckg_A pckg_B)) { $mwt_pckg->Radiobutton( -text => " $type", #modified here as you suggested. -value => $type, -variable => \$package, #)->grid(-sticky => 'w', -column => 1, -row => 2); )->grid(-sticky => 'w', -column => 1, -row => 2, -columnspan=>20, +-padx => 50, );

    However, it just doesn't works as I wish.

    Note, if I modify the code replacing the current grid position with pack, the gui doen't pop up at all.

      Make a new Frame for the radio buttons, and use grid to add it to the page.

      my $rb_frm = $mwt_pckg->Frame()->grid( -sticky => 'w', -column => 1, -row => 2, -columnspan => 20, -padx => 50, ); my $package = 'normal'; foreach my $type (qw(normal pckg_A pckg_B)) { $rb_frm->Radiobutton( -text => " $type", -value => $type, -variable => \$package, -command => sub { say $package; }, )->pack; }

        Thanks a bunch stefbv (your " Make a new Frame for the radio buttons" do the trick :)) and those all who contributed your ideas. I finally able to get what I looks for with slightly modification of stefbv sample code, to make the radio button horizontal, posted it here for reference for those who need help as me. It looks like below:-

        my $rb_frm = $mwt_pckg->Frame()->grid( -sticky => 'w', -column => 1, -row => 2, # -columnspan => 20, # -padx => 50, ); my $package = 'normal'; foreach my $type (qw(normal pckg_A pckg_B)) { $rb_frm->Radiobutton( -text => " $type", -value => $type, -variable => \$package, -command => sub { say $package; }, )->pack (-side => 'left'); #This line to make it horizontal }