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

9.3. The Scrollable Region

The scrollable area is the portion of the canvas widget that you want the user to be able to see. If you don't create a scrollable area (by using the -scrollregion option), the user can scroll infinitely in any direction and the scrollbars don't reflect where items on the canvas are.

Figure 9.2 shows an example of the scrollable area compared with the area that is visible in the canvas. If these two areas are the same size, you don't need scrollbars on the canvas (if you use scrollbars, their sliders will completely fill the trough area).

Figure 9.2. Scrollable area compared with visible area

The arrows on the axis markers in Figure 9.2 indicate that the canvas can still be larger than the indicated scrolling area. For instance, if you decide to insert a circle beyond the scrolling area, you have to adjust the scrollable area so the user will be able to see the new circle.

The best way to do this is to use the bboxmethod, which returns a bounding box for all items that match the tags you send it. Here's what the code looks like:

$canvas->configure(-scrollregion => [ $canvas->bbox("all") ]);

Calling this after you add or remove items to the canvas resets the scroll region to where it needs to be. Of course, if you are adding many different items all at once, you should wait until after you have added them all and then update the scroll region.

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