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

In reply to Re: Re: Tk centering main window on screen. by spikey_wan
in thread Tk centering main window on screen. by spikey_wan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.