Button Box are a convenient way to quickly layout a group of
buttons. They come in both horizontal and vertical flavors. You
create a new Button Box with one of the following calls, which
create a horizontal or vertical box, respectively:
$button_box = new Gtk::HButtonBox();
$button_box = new Gtk::VButtonBox();
The only attributes pertaining to button boxes effect how the
buttons are laid out. You can get and change the spacing between
the buttons with:
$button_box->set_spacing_default( $spacing );
$button_box->get_spacing_default();
The second attribute that we can access effects the layout of
the buttons within the box. It is set using:
$button_box->set_layout_default( $layout );
The
$layout
argument can take one of the following values:
'default_style'
'spread'
'edge'
'start'
'end'
The current layout setting can be retrieved using:
$button_box->get_layout_default();
Buttons are added to a Button Box using the usual function:
$button_box->add( $button );
Here's an example that illustrates all the different layout settings for Button Box.
#!/usr/bin/perl -w use Gtk; use strict; set_locale Gtk; init Gtk; my $false = 0; my $true = 1; my $window; my $main_vbox; my $vbox; my $hbox; my $frame_horizontal; my $frame_vertical; # Create the window $window = new Gtk::Window( "toplevel" ); $window->set_title( "Button Boxes" ); $window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } ); $window->border_width( 10 ); # Create the main vertical box. $main_vbox = new Gtk::VBox( $false, 0 ); $window->add( $main_vbox ); # Create a horizontal frame $frame_horizontal = new Gtk::Frame( "Horizontal Button Boxes" ); $main_vbox->pack_start( $frame_horizontal, $true, $true, 10 ); # Create a vertical box to put inside the horizontal frame $vbox = new Gtk::VBox( $false, 0 ); $vbox->border_width( 10 ); $frame_horizontal->add( $vbox ); $vbox->pack_start( create_bbox( $true, "Spread (spacing 30)", 30, 85, 20, 'spread' ), $true, $true, 0 ); $vbox->pack_start( create_bbox( $true, "Spread (spacing 40)", 40, 85, 20, 'spread' ), $true, $true, 0 ); $vbox->pack_start( create_bbox( $true, "Edge (spacing 30)", 30, 85, 20, 'edge' ), $true, $true, 5 ); $vbox->pack_start( create_bbox( $true, "Start (spacing 20)", 20, 85, 20, 'start' ), $true, $true, 5 ); $vbox->pack_start( create_bbox( $true, "End (spacing 10)", 10, 85, 20, 'end' ), $true, $true, 5 ); # Create a vertical frame $frame_vertical = new Gtk::Frame( "Vertical Button Boxes" ); $main_vbox->pack_start( $frame_vertical, $true, $true, 10 ); # Create a horizontal box to put inside the vertical frame. $hbox = new Gtk::HBox( $false, 0 ); $hbox->border_width( 10 ); $frame_vertical->add( $hbox ); $hbox->pack_start( create_bbox( $false, "Spread (spacing 5)", 5, 85, 20, 'spread' ), $true, $true, 0 ); $hbox->pack_start( create_bbox( $false, "Edge (spacing 30)", 30, 85, 20, 'edge' ), $true, $true, 5 ); $hbox->pack_start( create_bbox( $false, "Start (spacing 20)", 20, 85, 20, 'start' ), $true, $true, 5 ); $hbox->pack_start( create_bbox( $false, "End (spacing 20)", 20, 85, 20, 'end' ), $true, $true, 5 ); $window->show_all(); main Gtk; exit( 0 ); ### Subroutines # Create a Button Box with the specified parameters. The first # parameter is a true or false value specifying if the button box is # horizontal. The second parameter is the title of the button box. # The third is the spacing of the button box. The fourth and fifth # are the width and height of the buttons. And the sixth parameter is # the layout of the button box. sub create_bbox { my ( $horizontal, $title, $spacing, $child_w, $child_h, $layout ) = @_; my $frame; my $bbox; my $button; $frame = new Gtk::Frame( $title ); # Create the button box if ( $horizontal ) { $bbox = new Gtk::HButtonBox(); } else { $bbox = new Gtk::VButtonBox(); } $bbox->border_width( 5 ); $frame->add( $bbox ); # Set the appearance of the Button Box $bbox->set_layout( $layout ); $bbox->set_spacing( $spacing ); $bbox->set_child_size( $child_w, $child_h ); # Add buttons to the button box $button = new Gtk::Button( "OK" ); $bbox->add( $button ); $button = new Gtk::Button( "Cancel" ); $bbox->add( $button ); $button = new Gtk::Button( "Help" ); $bbox->add( $button ); return ( $frame ); } # END EXAMPLE PROGRAM

ButtonBox Example Screenshot