Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Help needed regarding creating a subroutine to fit and view all items in a Tk::Canvas

by KuntalBhusan (Acolyte)
on Nov 01, 2012 at 14:23 UTC ( #1001834=perlquestion: print w/ replies, xml ) Need Help??
KuntalBhusan has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I want to write a subroutine for Tk::Canvas so that when it is called it will enable the user to view all elements of a Tk ::Canvas which would be something like the ViewAll() function of Tk::AbstractCanvas or something better (I don't want to use Tk::AbstractCanvas for some reasons...). The code I have written is something like this :
sub fit_to_canvas { my ($xt0,$yt0,$xt1,$yt1) = $_canvas{0}->bbox('all'); if($xt0 != "") { my ($x0,$y0,$x1,$y1) = $_canvas{0}->bbox('all'); $_canvas{0}->xviewMoveto($x0); $_canvas{0}->yviewMoveto($y1); $_canvas{0}->configure(-scrollregion => [$x0,$y0,$x1,$y1]); }## end of if not empty canvas }
But it does not seen to work properly and do what I need.... Any help will be highly appreciated in this regard.. Thanks, Kuntal

Comment on Help needed regarding creating a subroutine to fit and view all items in a Tk::Canvas
Download Code
Replies are listed 'Best First'.
Re: Help needed regarding creating a subroutine to fit and view all items in a Tk::Canvas
by zentara (Archbishop) on Nov 01, 2012 at 16:15 UTC
    Try something like in this example code. After getting your bbox('all'), do your configure, then adjust the scrollbars.
    # add these lines to force scroll to the ends my @bbox = $can->bbox( 'img' ); $can->configure(-scrollregion => [@bbox] ); $can->xviewMoveto(1); $can->yviewMoveto(1);
    See example code in Tk photo pixel colors

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001834]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2015-07-07 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls