I spent multiple hours last night attempting to figure out just precisely how scrollbars work...I've read the documentation that comes with Tk along with looking at some books and I can't get a scrollbar to work with a fixed-size Canvas. I seem to be missing something...here are some examples of the code I've tried(This list is relatively long):

# $main is MainWindow my $canvas = $main->Scrolled('Canvas', -scrollbars => 'e', -height => 200, -width => 200, )->pack; $canvas->packPropagate(0);
Running this code produces a very thin window with no contents. Adding
-scrollregion => [0,0,200,200],
to the arguments given to Scrolled produces the same output.
Going about things in a slightly different way produces a window of the correct size:
my $frame = $main->Scrolled('Canvas', -scrollbars => 'e', )->pack; my $canvas = $frame->Subwidget('canvas'); $canvas->configure(-height => 200, -width => 200); $canvas->packPropagate(0);
Yet, when I insert some widgets, and just to test it lets add in
foreach (1..20) { $canvas(or $frame)->Label(-text => 'test')->pack; }
the contents of the canvas obviously exceed its specified height yet the scrollbar doesn't let me scroll up/down. Adding -scrollregion => [0,0,200,200] to the arguments given to configure affects nothing.

In a final attempt to get a scrollbar to work with my canvas, I tried using the Scrollbar method:
my $canvas = $main->Canvas(-height => 200, -width => 200, )->pack(-side => 'left'); $canvas->packPropagate(0); my $scrollbar = $main->Scrollbar( -orient => 'vertical', -command => ['yview' => $canvas], )->pack(-fill => 'y', -side => 'right');
Clicking on the scrollbar yields a slew of error messages. I've tried a few different lists in the -command option including
['yview', $canvas, 'scroll', 1, 'units']
and to no avail. Any help here would be appreciated. I am assuming that I am missing something that is very simple here, possibly a need to inform the Canvas of the Scrollbar or something. I've looked online yet can only find examples of Scrollbars used with Listboxes, thus not helping me here. Thank you,
-Eric

In reply to 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.