in reply to Tk centering main window on screen.

I just tried your code, and didn't see any differences in the location of the upper left corner of the popup window, with or without minsize. So I guess you are making an assumption, based on the appearance of the smaller popup seeming to be centered. The anchor is the upper left corner of the window, not the center of the window.

I'm using linux Tk804.027


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: Tk centering main window on screen.

Replies are listed 'Best First'.
Re: Re: Tk centering main window on screen.
by spikey_wan (Scribe) on May 28, 2004 at 09:49 UTC
    OK, consider the following example. The windows are exactly the same size, yet appear in different positions. What do I need to to do the 2nd popup to get it to be centered in the main window?

    use strict; use warnings; use Tk; my $mw = MainWindow -> new; $mw -> minsize (qw(600 400)); my $button = $mw -> Button ( -text => '1st popop', -command => \&popup1, ) -> pack; my $other_button = $mw -> Button ( -text => '2nd popup', -command => \&popup2, ) -> pack; MainLoop; sub popup1 { print "Main window geometry = ".$mw -> geometry."\n"; my $popup1 = $mw -> Toplevel; $popup1 -> withdraw; for (1..10) { my $label = $popup1 -> Label ( -text => "This is a very very very long label", ) -> pack; } $popup1 -> Popup ( -popover => $mw, -overanchor => 'c', -popanchor => 'c', ); print "1st popup geom = ".$popup1 -> geometry."\n\n"; } sub popup2 { print "Main window geometry = ".$mw -> geometry."\n"; my $popup2 = $mw -> Toplevel; $popup2 -> withdraw; my $label = $popup2 -> Label ( -text => "This is a label", ) -> pack; $popup2 -> minsize (qw(162 190)); $popup2 -> Popup ( -popover => $mw, -overanchor => 'c', -popanchor => 'c', ); print "2nd popup geom = ".$popup2 -> geometry."\n\n"; }