An Example:
use Tk; use Tk::Canvas; use Tk::Label; my $mw = tkinit(-title, 'Canvas'); #$mw->geometry('250x250'); my $frame = $mw->Frame(-width, 250, -height, 250)->pack(-fill, 'both', + -expand,1); my $canvas = $frame->Scrolled('Canvas', -width, 600, -height, 600, -scrollbars, 'osoe' )->pack(-fill,'both',-expand,1); my $btn = $mw->Button(-text, "Add Stuff", -command,\&addStuff) ->pack(); MainLoop; sub addStuff{ $canvas->createText(500, 500, -text, "Some text @ 500, 500." ); $canvas->createRectangle( 50, 50, 110, 110, -fill, 'red'); $canvas->createRectangle( 150, 150, 210, 210, -fill, 'green'); $canvas->createRectangle( 250, 250, 310, 310, -fill, 'blue'); $canvas->createText(20, 20, -text, "Some text @ 20, 20." ); # # Your can use an array for your bounding box # commented out to show both ways to set the scrollregion # Just make sure you are 1 less on lower right and bottom # Or you will have out of bounds array... easy to forget # if you don't use a frame with your canvas #$canvas->configure(-scrollregion => [ 0, 0, 599, 599]); $canvas->configure(-scrollregion => [$canvas->bbox('all')]); }

Update: commented out initial geometry
JamesNC

In reply to Re: A Canvas and a Scrollbar with Tk by JamesNC
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.