Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Perl Tk Resize Question

by capfan (Sexton)
on Nov 21, 2020 at 10:30 UTC ( [id://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: 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);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found