Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Perl Tk Resize Question

by capfan (Sexton)
on Nov 21, 2020 at 10:30 UTC ( #11123961=note: print w/replies, xml ) Need Help??

in reply to Perl Tk Resize Question

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:, 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);

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123961]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-03-20 15:07 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.