http://qs321.pair.com?node_id=306780

Gwalchmai has asked for the wisdom of the Perl Monks concerning the following question:

I am just not seeing how to resize a Tk window.

Below is a simple example. The window is so small that the title is obscured.

How can I have the window centered on the screen and enlarged? I eventually want to have child screens that are the same size as the main window, that appear in the center and completely cover the main window.

I would be greatful for any help.

Thanks,
Doug

use Tk; my $main = MainWindow->new; $main->title("Resize Test"); $main->width => 300; $main->height => 300; $main->Button( -text => "Exit Program", -command => sub { exit } )->pack(); MainLoop;

janitored by ybiC: Balanced <code> tags to facilitate easy code download

Replies are listed 'Best First'.
Re: Tk Window Size
by pg (Canon) on Nov 13, 2003 at 12:52 UTC

    One way is to call geometry().

    use Tk; use strict; my $main = MainWindow->new(-title => "Resize Test"); $main->geometry("600x400"); $main->Button( -text => "Exit Program", -command => sub { exit } )->pack(); MainLoop;
Re: Tk Window Size
by Anonymous Monk on Nov 13, 2003 at 12:57 UTC
    $main->width => 2000; $main->height => 1000;
    is just wrong, see
    perl -MO=Deparse $main->width => 2000; $main->height => 1000; ^Z $main->width, '???'; $main->height, '???'; - syntax OK
Re: Tk Window Size
by zentara (Archbishop) on Nov 13, 2003 at 16:50 UTC
    You may find this example handy and informative:
    #!/usr/bin/perl use Tk; my $mw = new MainWindow; my $currentSize = $mw->reqwidth . "x" . $mw->reqheight; $mw->bind( '<Configure>', [ \&OnResize, \$currentSize ] ); MainLoop; sub OnResize { my ( $mw, $oldSize ) = @_; my $newSize = $mw->width . "x" . $mw->height; if ( $$oldSize ne $newSize ) { ## Resize has occurred do something: printf( "Resize happened - old size: %s, new size: %s\n", $$oldSize, $newSize ); ## set the old size to the new size $$oldSize = $newSize; } }