You need to resort to some using some flags and tricks. First, you will need to pack your canvas with -fill=>0, and -expand=>1 so it won't automatically resize. Then when you detect a $mw resize, resize your canvas manually. Here is a way to detect when a resize finishes. I'm sure there is a more refined way, but I don't feel like hacking for it. :-) By the way, if you are having trouble resizing automatically, there may be some other problem in your code. This requires you to right click on the $mw after you finished resizing.

P.S. The reason your Button-1-Release dosn't work, is because you are NOT in the $mw when you do a resize, you are doing a WINDOWMANAGER event. So you have to realize your mouse is not in the Tk window anymore, during a resize.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; my $current_size = $mw->reqwidth . "x" . $mw->reqheight; my $old_current_size = $current_size; my $canvas = $mw->Canvas(-width => 300, -height => 300, -bg => 'black', )->pack(); $mw->bind( '<Configure>', sub{ &OnResize }); my $leave = 0; $mw->bind( '<Leave>',sub { $leave = 1; } ); $mw->bind( '<Enter>',sub { $leave = 0; &OnResize; } ); $mw->bind( '<3>',sub { print "1\n"; my $width = $mw->width - 10; my $height = $mw->height - 10;; $canvas->configure(-width=> $width, -height => $height); $mw->update; } ); MainLoop; sub OnResize { my $current_size = $mw->width . "x" . $mw->height; if( $leave == 1) {return } if($old_current_size eq $current_size){return} ## Resize has occurred do something: printf( "Resize happened - old size: %s, new size: %s\n", $old_current_size, $current_size ); ## set the old size to the new size $old_current_size = $current_size; }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Perl Tk Resize Question by zentara
in thread Perl Tk Resize Question by Anonymous Monk

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.