For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > September 2004 > window position on resize oddities









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author window position on resize oddities
zentara

2004-09-04, 8:56 pm


Hi,
Can anyone explain why position dosn't quite work right
after a window resize? There seems to be some negative
position values coming into play. Try the following 3
geometry statements in the resize sub. The '+20+20'
dosn't seem to hold position, but the '+40+40' does.

I'm guessing the new geometry request, somehow adds a -20
to the x and y values as it re-origins itself at 0,0.
So I seem to need to double the '+20+20' to '+40+40', to
maintain position.

Is that the deal?, that if you have a second geometry statement
in a program, the window always resets it's origin to 0,0 and
accumulates a negative position value?

Is it my fvwm2 Window Manager? I'm using Tk804.027.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = MainWindow->new(-background => 'black');
$mw->geometry( '700x370+20+20' );

$mw->Button(-text =>'Resize',
-command => [\&resize]
)->pack();

$mw->Button(-text =>'Exit',
-command => sub{ Tk::exit },
)->pack();
MainLoop;

sub resize{
my $newwidth = 700;
my $newheight = 700;

#this one dosn't go to 0,0
# $mw->geometry($curwidth .'x'. $newheight );

#this one seems to go to 15,0
$mw->geometry($newwidth .'x'. $newheight . '+20+20' );

#this one comes close
# $mw->geometry($curwidth .'x'. $newheight . '+40+40' );
}

__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
zentara

2004-09-06, 4:01 pm

On Sat, 04 Sep 2004 16:43:58 -0400, zentara <zentara@highstream.net>
wrote:

>Can anyone explain why position dosn't quite work right
>after a window resize? There seems to be some negative


Never mind, I have found a way to do it.

The mainwindow needs to be withdrawn before resizing and moving.

So this works fine:

sub resize{
my $newwidth = 700;
my $newheight = 700;

$mw->withdraw;
$mw->geometry($newwidth .'x'. $newheight . '+20+20' );
$mw->deiconify;

}






--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com