The Scrollbar widget
For more flexibility with a scrollbar, you can use
the Scrollbar widget. To do so, you need to create the target
widget to scroll. Set the -xscrollcommand
or -yscrollcommand
option as appropriate,
configure the scrollbar to talk to the widget, and position the
scrollbar and target widget next to one another. For
example:
$scrollbar = $mainwindow->Scrollbar(-orient => 'vertical'); $listbox = $mainwindow->Entry(-yscrollcommand => ['set' => $scrollbar]); $scrollbar->configure(-command => ['yview' => $listbox]); $scrollbar->pack(-side => 'right', -fill => 'y'); $listbox->pack(-side => 'left', -fill => 'both');
First, we create the scrollbar with vertical orientation
(which is actually the default). Next, we create the Listbox
widget with the -yscrollcommand
option to define a callback when the widget is scrolled
vertically. The scrollbar is then configured with a callback that
says to inform the Listbox widget when it is clicked vertically.
Finally, the Scrollbar and Listbox widgets are packed
side-by-side. See further discussion of the Scrollbar widget later
in this chapter for more information.
Get Perl in a Nutshell, 2nd Edition 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.