Creating a Canvas

It’s easiest to always use the Scrolled method to create a Canvas, unless you know for sure 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 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 Canvas method returns a reference to the newly created Canvas widget.

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