Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl Monk, Perl Meditation
 
PerlMonks  

Perl/Tk Scroll

by mikasue (Friar)
on Oct 31, 2011 at 01:07 UTC ( #934798=perlquestion: print w/ replies, xml ) Need Help??
mikasue has asked for the wisdom of the Perl Monks concerning the following question:

I am developing a Perl Tk app and have created a nice background image that I want to display throughout for each screen. So I decided to use a Canvas widget to draw the background image then everything else on top of it. Well it looks great but even though I used Scrolled("Canvas") The window does not scroll when I reduce the resolution from 1280x800 to 1024x768 to 800x600.

I could create a background image for each size and check the screen size before I load the main screen and render the canvas according to the resolution. But i'm sure there is a better way to just make this Canvas scroll.

I've tried to use Scrolled, Pane, even attach scrollbars -- Nothing is scrolling this background image. Any suggestions, advice or the solution :-) would be appreciated.

use Tk; my $mw = MainWindow->new; my $mycanvas = $mw->Scrolled("Canvas",-width=>800, -height=>600, -scro +llbars=>'se'); my $headerpicpath = $Bin."logo.gif"; my $pic = $mw->Photo(-file=>$headerpicpath); $mycanvas->createImage(425,400,-image=>$pic);

Comment on Perl/Tk Scroll
Download Code
Re: Perl/Tk Scroll
by keszler (Priest) on Oct 31, 2011 at 02:30 UTC

    You need to set the canvas' scrollregion to the size of the image (plus anything else on the canvas).

    use strict; use Tk; my $mw = MainWindow->new; my $mycanvas = $mw->Scrolled( "Canvas", -width=>800, -height=>600, -scrollregion => [0,0,1019,1600], -scrollbars=>'se' )->pack(-expand => 1, -fill => 'both'); my $headerpicpath = '/some/path/image_1019_wide_1600_high.gif'; my $pic = $mw->Photo(-file=>$headerpicpath); $mycanvas->createImage(0,0,-image=>$pic,-anchor=>'nw'); MainLoop;
      THANK YOU!!!!!!
Re: Perl/Tk Scroll
by zentara (Archbishop) on Oct 31, 2011 at 10:50 UTC
    As Keszler said You need to set the canvas' scrollregion to the size of the image (plus anything else on the canvas).

    You will probably need this trick eventually for resizing the canvas's scrollregion.

    $canvas->configure(-scrollregion=> [$canvas->bbox('all')] );
    After you add things to the canvas, you reset the scrollregion to the bbox ( bounding box) for 'all' items. Works great.

    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://934798]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-04-18 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls