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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access