I had the same issue today and found this thread. Yes, it is old, but I would like to add another solution in case someone needs it.

You can use a timer to wait for a moment before you do the resize. Cancel the timer if the MainWindow resizes again within a certain time and start it anew.

Sample code:

#!perl use strict; use warnings; use Tk; use v5.16; # Skript zum manuellen resizen der Canvas nach Änderung der Größe des +MainWindow. # Man muss nochmal einen Rechtsklick machen. # Quelle: https://www.perlmonks.org/bare/?node_id=581309, abgerufen 20 +20-11-21 my $mw = Tk::MainWindow->new; 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(); $canvas->update; # important to call this before binding <configure> e +vent my $after_resize_timer_id; $mw->bind('<Configure>' => sub { say "MW resized"; # reset timer again, if it was set $mw->afterCancel($after_resize_timer_id) if defined $after_resize_ +timer_id; # set timer # if MW doesn't resize again within a second or so, resize Canvas # if it does, reset timer to wait for a second or so $after_resize_timer_id = $mw->after(500, sub{ say "Update canvas"; my $width = $mw->width; my $height = $mw->height; $canvas->configure(-width => $width, -height => $height); $canvas->update; }); }); $mw->MainLoop; exit(0);

In reply to Re: Perl Tk Resize Question by capfan
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.