in reply to perltk autoresize following users resize
#!/usr/bin/perl use Tk; my $mw = MainWindow->new; $mw->bind( "<Configure>" => sub { print "reconfigure ".ref($_[0]). +"\n" } ); my $topFr = $mw->Frame ->pack( -fill => "both", -expand => 1 ); $topFr->Button( -text => "bigger", -command => sub { changeSize(50) } +) ->pack( -side => "bottom", -expand => 1 ); $topFr->Button( -text => "smaller", -command => sub { changeSize(-50) +} ) ->pack( -side => "bottom", -expand => 1 ); my $interior = $topFr->Frame( -label => "Hello world", -height => 100, -width => 100, -background => "white", -relief => "groove" ) ->pack( -side => "bottom", -fill => "both", -expand => 1 ); $interior->packPropagate(0); MainLoop; sub changeSize { my ($sizeDelta) = @_; $interior->configure( -width => $interior->width+$sizeDelta, -height => $interior->height+$sizeDelta ); printf("interior %d x %d, topFr %d x %d\n", $interior->width, $interior->height, $topFr->width, $topFr->height ); }
#!/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; $mw->bind( '<Configure>', sub{ &OnResize }); my $leave = 0; $mw->bind( '<Leave>',sub { $leave = 1; } ); $mw->bind( '<Enter>',sub { $leave = 0; &OnResize; } ); 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perltk autoresize following users resize
by rpelak (Sexton) on Aug 19, 2008 at 15:10 UTC | |
by zentara (Cardinal) on Aug 19, 2008 at 17:01 UTC | |
by rpelak (Sexton) on Aug 19, 2008 at 18:20 UTC | |
by zentara (Cardinal) on Aug 19, 2008 at 19:10 UTC | |
by rpelak (Sexton) on Aug 19, 2008 at 21:07 UTC | |
|