home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeMastering Perl/TkSearch this book

23.4. The Adjuster Widget

There are times you would like the user to have control over how large a frame is in part of the application. Let's say you're listing a large number of font styles along the left side of the application, and the right side of the application contains a Text widget. It would be nice if users could make the font styles list wider or smaller depending on their preferences. We can do this using the Adjuster widget.

Here's a simple example using two frames that contain a Listbox and a Text widget, respectively:

use Tk;
use Tk::Adjuster;

$mw = MainWindow->new(-title => "Adjuster example");

$leftf = $mw->Frame->pack(-side => 'left', -fill => 'y');
$adj = $mw->Adjuster(-widget => $leftf, -side => 'left')
  ->pack(-side => 'left', -fill => 'y');
$rightf = $mw->Frame->pack(-side => 'right', -fill => 'both', -expand => 1);

# Now put something into our frames.
$lb = $leftf->Scrolled('Listbox', -scrollbars => 'osoe')
  ->pack(-expand => 1, -fill => 'both');
$lb->insert('end', qw/normal bold italics code command email emphasis   
                      emphasisBold Filename FirstTerm KeyCode KeySymbol/);
$rightf->Scrolled('Text', -scrollbars => 'osoe')
  ->pack(-expand => 1, -fill => 'both');


You can see in Figure 23-11 that the thin line with the small box at the bottom is our adjuster. If you hover your mouse over the line, the cursor will change to a horizontal double-ended arrow, indicating you can click and drag. As you drag to the right, the Listbox becomes larger. As you drag to the left, the Listbox becomes smaller.

Figure 23-11

Figure 23-11. Window with Adjuster between Listbox and Text Widgets

Instead of calling pack on the Adjuster widget, you can call packAdjust, which shortens your argument list and eliminates having to use any pack-specific options:

$adj1->packAdjust($leftf, -side => 'left');

The options you can use to customize the Adjuster include:

-restore => 1 | 0
When the top level window changes size, setting -restore to 1 will make the Adjuster keep room for itself in the window.

-side => 'left' | 'right' | 'top' | 'bottom'
Indicates where the managed widget lies in relation to the Adjuster. Values of 'top' or 'bottom' will cause the Adjuster to be horizontal and manage height instead of width.

-widget => widget
The widget to be managed by the adjuster.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.