Problem1.
I have a yellow rectangle on scrolled canvas...
#!/usr/bin/perl -w use Tk; use strict; # Main program / GUI setup my $mw = MainWindow->new; my $c = $mw->Scrolled('Canvas', -width => 200, -height => 200)->grid; $c->configure(-background =>'blue', -scrollregion => [ 0, 0, 500, 500 +]); #Grid $c->createGrid(0, 0, 10, 10); $c->createGrid(0, 0, 100, 100, -lines => 1, -dash => '.-'); $c->pack(-expand => 1, -fill => 'both'); my $rect = $c->createRectangle(20, 20, 40, 40, -outline => 'yellow', -fill => 'yellow'); MainLoop;
..which is the best way to make the rectangle float in the same place regardless of in which direction the canvas in scrolled?


Problem2.
Here are two rectangles red and green on a scrolled canvas...
#!/usr/bin/perl -w use Tk; use strict; my $mw = MainWindow->new; $mw->geometry('300x300'); #try this my $c = $mw->Scrolled('Canvas', -width => 200, -height => 200, -background =>'blue', -scrollregion => [ 0, 0, 500, 500 ] )->pack(-expand => -2, -fill => 'both'); $c->createRectangle(100, 100, 150, 150, -fill => 'red'); $c->createRectangle(100, 400, 150, 450, -fill => 'green'); my $plus = $c->Button( -text => ' + ', -command => sub {$c->scale("all", 125, 125, 2, 2); } ); $plus->pack; my $minus = $c->Button( -text => ' . ', -command => sub {$c->scale("all", 125, 125, 0.5, 0.5); } ); $minus->pack; MainLoop;
...when the canvas is zoomed by 2x by clicking the '+' button the canvas remains in the same size which means that the areas not fitting in the new zoom disapear outside the visible area. (For example it is not possible to scroll to the green rectangle when zooming once.)How is it possible to zoom in a way so that the areas over which it is possible to scroll are expanded to contain the areas that do not fit to the new larger zoom. Thank you very much for your advice.

In reply to Two questions regarding -tk-canvas by tamaguchi

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.