Gossamer Forum
Home : General : Perl Programming :

Perl/Tk window size bug help

Quote Reply
Perl/Tk window size bug help
I'm getting a weird bug that resizes my main window to its minimal dimensions. I first create my main window, then I make a function that creates a pane widget (a frame widget but scrollable) and pack it into the main window. The weird part is if I call the pane creation function right after creating the main window, the main window dimensions are preserved. But if I link the pane creation function to a menu bar option call, the main window resizes to its minimal dimensions (defined by $main->minsize). Anyone know how to preserve the main window dimensions through a menu bar function call?

Here is the code I am using:
Code:
#!/usr/bin/perl

use strict;

use Tk;
use Tk::Pane;

my $main = MainWindow->new;

$main->minsize(qw(175 125));

$main->configure(-menu => my $menubar = $main->Menu);

my $file_menu = $menubar->cascade(-label => '~File');

$file_menu->command(
-label => 'Load Picture',
-underline => 0,
-command => sub {create_pane();}
);

#create_pane();

MainLoop;

sub create_pane {
my $main_pane = $main->Scrolled(
'Pane',
-width => 1024,
-height => 768,
-background => 'black'
);

$main_pane->pack(-expand => 1, -fill => 'both');
}

-James jchen578@hotmail.com
Quote Reply
Re: [jchen578] Perl/Tk window size bug help In reply to
The window isn't shrinking as you think. You have not told Tk you want any specific size other than a bare minimum, thus, it will not allocate 1024x768 for your pane widget until the "Load Picture" callback is executed.

You can use the following code to set the default size of the window:
Code:
$main->geometry("1024x768");

you can also force it back to that default size at any point by calling geometry with an emptry string.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Perl/Tk window size bug help In reply to
Works great now. Thanks!

-James