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'); MainLoop;
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, ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.