First let me answer your immediate question thru a piece of simple demo code:
use Tk; use strict; use warnings; my $main = new MainWindow(); my $canvas = $main->Scrolled('Canvas', -scrollbars => 'se', -height => 400, -width => 400, )->pack; $canvas->createOval(100,100,500,500); MainLoop;
The code has been tested and the scrollbar worked. The demo code simply creates a canvas (which can be imagined as a “window”, through which you can peek into the world), then draws an oval that exceeds the canvas (so part of the oval is beyond the “window”), now you use the scrollbars to move the “window” and peek at different portions of the oval.
Now the answer to a question you didn’t ask. You tried to add Labels on top of canvas, and that is not the best practice for GUI programming. It is not only true to Perl/Tk, but any GUI platform: Canvas is not used to hold other GUI components, but only drawing (including text). I saw that you tried to add Label on canvas, and that is discouraged. To add text on canvas, use:
$canvas->createText(…);
In reply to Re: A Canvas and a Scrollbar with Tk
by pg
in thread A Canvas and a Scrollbar with Tk
by Silverstrike
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |