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

Currently I have a delete button which is as wide as the application window.
$self->{delete_button} = $mw->Button( -text => 'Delete', -command=> [ +\&delete , $self ] )->pack( -expand => '1', -fill => 'both' );
Now I need to add an undelete button. How do I divide this space between two buttons equally with the pack manager ( so that they together still fill all available space )?
  • Comment on How can I use the pack manager to divide space equally between two buttons?
  • Download Code

Replies are listed 'Best First'.
Re: How can I use the pack manager to divide space equally between two buttons?
by Eily (Monsignor) on Jan 28, 2015 at 23:43 UTC

    My crystal ball might be broken because it won't tell me what module you are using. But for some reason I think you are doing Tk GUIs, tkguifan. Just a huncht. But please do think about giving more information next time.

    So, on the topic of expansion, the documentation says:

    If a master window is so large that there will be extra space left over after all of its slaves have been packed, then the extra space is distributed uniformly among all of the slaves for which the -expand option is set. Extra horizontal space is distributed among the expandable slaves whose -side is left or right, and extra vertical space is distributed among the expandable slaves whose -side is top or bottom.
    -side => 'left' and -side => 'right' might do what you want. If not, you will probably need to give more information.

      This almost worked. Unfortunately it mixed it up with an other element that has expand option, and this other element was sandwiched between the two buttons ( which were correctly placed left and right ). I had to introduce a dummy frame:
      # dummy frame to contain buttons $self->{delete_frame}=$mw->Frame() ->pack(-expand => '1', -fill => 'both' ); # buttons $self->{delete_button}=$self->{delete_frame}->Button(-text=>'Delete' +,-command=>[ \&delete , $self ]) ->pack(-side=>'left', -expand => '1', -fill => 'both' ); $self->{undelete_button}=$self->{delete_frame}->Button(-text=>'Undel +ete',-command=>[ \&undelete , $self ]) ->pack(-side=>'right', -expand => '1', -fill => 'both' );