Chapter 49. Frames

Inheritance Hierarchy

Object
   +--- Widget
         +--- Container
               +--- Bin
                     +--- Frame
         

Frames can be used to enclose one or a group of widgets with a box which can optionally be labelled. The position of the label and the style of the box can be altered to suit.

A Frame can be created with the following function:

$frame = new Gtk::Frame( $label );

The label is by default placed in the upper left hand corner of the frame. A null string for the $label argument will result in no label being displayed. The text of the label can be changed using:

$frame->set_label( $label );

The position of the label can be changed using this function:

$frame->set_label_align( $xalign, $yalign );

where $xalign and $yalign take values between 0.0 and 1.0. $xalign indicates the position of the label along the top horizontal of the frame. $yalign is not currently used. The default value of $xalign is 0.0 which places the label at the left hand end of the frame.

The next function alters the style of the box that is used to outline the frame.

$frame->set_shadow_type( $type );

The $type argument can take one of the following values:

'none'
'in'
'out'
'etched_in' (the default)
'etched_out'

49.1. Frame Example

The following code example illustrates the use of the Frame widget.

Frame Example Source

      
#!/usr/bin/perl -w

use Gtk;
use strict;

set_locale Gtk;
init Gtk;

my $false = 0;
my $true = 1;

my $i;

my $window;
my $frame;
my $button;


# Create the Window
$window = new Gtk::Window( "toplevel" );
$window->set_title( "Frame Example" );
$window->signal_connect( "destroy", sub { Gtk->exit( 0 ); } );
$window->set_usize( 300, 300 );
$window->border_width( 10 );

# Create a Frame
$frame = new Gtk::Frame();
$window->add( $frame );

# Set the frame's label
$frame->set_label( "Gtk Frame Widget" );

# Align the label at the right of the frame
$frame->set_label_align( 1.0, 0.0 );

# Set the style of the frame
$frame->set_shadow_type( 'etched_out' );

$frame->show();
$window->show();

main Gtk;
exit( 0 );



# END EXAMPLE PROGRAM
      
   

Frame Example Screenshot