Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You may be looking for $canvas->bbox('all'), also see Two questions regarding -tk-canvas
#!/usr/bin/perl use Tk; use Tk::Canvas; use Tk::Label; my $mw = tkinit(-title, 'Canvas'); $mw->geometry('250x500'); my $frame = $mw->Frame(-width, 250, -height, 250)->pack(-fill, 'both', + -expand,1); my $canvas = $frame->Scrolled('Canvas', -width, 300, -height, 300, -bg=>'white', -scrollbars, 'osoe' )->pack(-fill,'both',-expand,1); my $btn = $mw->Button(-text, "Add Stuff", -command,\&addStuff) ->pack(); my $btn1 = $mw->Button(-text, "Add More Stuff", -command,\&addmoreStuf +f) ->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')]); } sub addmoreStuff{ $canvas->createText(1500, 1500, -text, "Some text @ 1500, 1500." ); $canvas->createRectangle( 5000, 5000, 1100, 1100, -fill, 'red'); $canvas->createRectangle( 1500, 1500, 2100, 2100, -fill, 'green'); $canvas->createRectangle( 2500, 2500, 3100, 3100, -fill, 'blue'); $canvas->createText(2000, 10, -text, "Some text @ 2000, 10." ); # # 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')]); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: getting visible area of Tk::Scrolled? by zentara
in thread getting visible area of Tk::Scrolled? by halley

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found