9.1. Creating a Canvas

I recommend that you always use the Scrolled method to create a canvas unless you know for sure that your canvas is going to be a fixed size that will fit in the window:

$canvas = $mw->Canvas( [ option => values, ... ] )->pack();
# or...
$canvas = $mw->Scrolled('Canvas', [ option => values, ... ])->pack();

The first line creates just a canvas and the second creates a canvas with scrollbars. (See Chapter 6, for more information on what else you can do with the Scrolled method.) To create a canvas widget, use the desired parent widget to invoke the Canvas method and pass any initial options in with their values. The Canvasmethod returns a reference to the newly created canvas widget.

Before we get into the options and methods available with a canvas widget, here are a few miscellaneous things you should know about using a canvas widget.

Get Learning 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.