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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.