Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

6.3. The Scrollbar Widget

Instead of automatically creating one or more scrollbars with the Scrolled method, you can use the Scrollbar widget method and perform the configuration yourself. It is better to create and configure your own scrollbars when you need to do something nonstandard, such as having one scrollbar scroll two listboxes.

6.3.1. Creating a Scrollbar Widget

To create the scrollbar, invoke the Scrollbar method from the parent widget. It returns a reference to the newly created scrollbar that you can use for configuration:

$scrollbar = $mw->Scrollbar([ options ...])

There are at least two other things you need to do to get a scrollbar working with another widget. First, create the to-be-scrolled widget and use the scrollbar with its -xscrollcommand or -yscrollcommand option. Then configure the scrollbar so that it knows to talk to that widget. Here's an example that creates a listbox widget (don't worry if you don't quite follow all of this now; I just want to show a complete example before we go on to talk about all the options):

# Create the vertical scrollbar $scrollbar = $mw->Scrollbar(); $lb = $mw->Listbox(-yscrollcommand => ['set' => $scrollbar]); #Configure the scrollbar to talk to the listbox widget $scrollbar->configure(-command => ['yview' => $lb]); #Pack the scrollbar first so that it doesn't disappear when we resize $scrollbar->pack(-side => 'right', -fill ...
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.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata