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

Tk Window Size

by Gwalchmai (Novice)
on Nov 13, 2003 at 12:44 UTC ( [id://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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found