Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Tk Window Size

by Gwalchmai (Novice)
on Nov 13, 2003 at 12:44 UTC ( #306780=perlquestion: print w/replies, xml ) Need Help??

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.


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; } }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-05-28 11:04 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.