Consider the following code:
use Tk; my %font=(-font=>[-family=>'Courier New',-size=>10]); my %width=(-width=>120); my $mw=new MainWindow; my $entry=$mw->Entry( %width, -relief=>'groove', -borderwidth=>5, -textvariable=>\$entry_text, %font )->pack; $entry->focus; $entry->bind('<Key-Return>',\&enter); my $text=$mw->Text( %font, %width, -height=>43 )->pack; #$mw->update; my $geom=$mw->geometry; print "geom: $geom\n"; $geom=~s/\+\d+\+\d+/+5+5/; $mw->geometry($geom); MainLoop; ################ prints: geom: 1x1+0+0
This creates a quite sizeable main window in Tk. I would like to position this window exactly at screen coordinates (5,5) to be fully visible. The idea is to query the geometry of the main window, replace the (x,y) coordinates with a regular expression and then set it again with the correct geometry string. However before invoking the main loop $mw->geometry returns '1x1+0+0'. Unly updating the window (commenting out #$mw->update;) builds the geometry string in the correct way. This results in the main window appearing in the wrong place and then instantly being removed which causes an unfavourable flickering. (Iconifying before and deiconifying after does not help!) Any thoughts on how to get the correct dimensions of the window without displaying it?

In reply to MainWindow geometry problem (update?) by chessgui

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.