I'd like to have a Canvas in a pane that 'fits' a window.

The canvas has a preordained size, and should not be drawn any larger than 1000x400. Should it be truncated to fit the window that it should appear with scrollbars. I've come close by responding to the event and changing the size of the inner pane, but attempt to control the scrollbars seem to cause the subroutine to exit, and the image gets mangled.

Can this layout be done without configuring elements on every change? > mwfOuter->configure( -scrollbars => $scrollbars); Here is the code:
#!/usr/bin/perl use Data::Dumper; # this implements 5 text fields that detect the modified properly use strict; use Tk; use Tk::Pane; use Tk::Photo; use Tk::PNG; my $mw = MainWindow->new; $mw->configure(-menu => my $menubar = $mw->Menu); my $app = $menubar->cascade( -label => '~*' ) ; # TODO -bitm +ap =>); my $file = $menubar->cascade( -label => '~File'); my $edit = $menubar->cascade(-label => '~Edit'); my $go = $menubar->cascade(-label => '~Go'); my $group7; my @checkboxes ; my $messageBar = $mw->Entry( )->pack( -side=>"bottom" ) ; $mw->geometry('600x650'); our $lastWidth; our $lastHeight; my $frame = $mw->Canvas( )->form( -top => '20' , -bottom => [ '%100' +, -40 ] , -right => '%95' , -left => '%5' ); # dynamic ! my $mwfOuter = $frame->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', -background=>'white', -width => 1000+23, -height => 400+23 # actula dim )->pack(); my $colourBars = $mw->Photo ( -file => 'colourBars.png' ); my $stackImage = $mw->Photo ( -file => 'stack.png' ) ; my $mwf = $mwfOuter->Pane( -sticky=>'nwse', -width => 1000 , -height => 400 )->p +ack() ; # actual dim # this totally works, but you have to set the height of $mwf to fit t +he window , which the user can change.... my $label = $mwf->Label( -image => $colourBars )->place( -x => 0 , -y + => 0 ); $mw->bind( '<Configure>' => [ \&gotResized ] ) ; # we need to change +some things... I'd rather live this to Tk sub gotResized{ my $current_size = $mw->width . "x" . $mw->height; if ($lastWidth == $mw->width and $lastHeight == $mw->height ) +{ return (0==0); }; # the card area is 10% of the width, and height -60; # set the mwfOuter to that size warn $current_size; my $scrollbars; my $w = 1100; if ($mw->width < 1100 ) { # 1.1 * 1000 $w = int ($mw->width * 0.9 ) ; $scrollbars .= 'oe'; } my $h = 400 ; if ($mw->height < 460 ) { $w = int ($mw->height - 60) ; $scrollbars .= 'os'; }; warn "scrollbars $scrollbars "; #$mwfOuter->configure( -scrollbars => $scrollbars ); #TODO why + does this not work? if ($w > 50 and $h > 50 ) { warn "Wanting to resize to $w x $h"; $mwf->configure( -width => $w , -height => $h ) ; $lastWidth = $mw->width ; $lastHeight =$mw->height; #warn "Resized" . Dumper (@_) ; }; return (0==0); }; MainLoop();

In reply to TK Geometry question. by kb3ien

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.