paulchernoch has asked for the wisdom of the Perl Monks concerning the following question:

I created a Tk::DialogBox object. When I show it, it appears half off screen. (I think it is trying to put the dialog in the middle of the screen, but I have a dual monitor and the result is not helpful.)

How do I specify the x,y coordinates for the dialog so I can move it to the true center of my screen? I am lost in a sea of geometry classes with no land in sight.

- Paul
  • Comment on How do I move a top level window in Tk?

Replies are listed 'Best First'.
Re: How do I move a top level window in Tk?
by paulchernoch (Acolyte) on May 12, 2009 at 22:06 UTC
    I figured it out. In my call to create the DialogBox I put this:
    -showcommand => sub { my($dlg) = @_; $dlg->geometry('900x600+400+250' +); }
    Just calling geometry() on creation was fine for the first time the dialog was posted, but if I close and then reopen the dialog, the coordinates revert to the bad location.

    This approach to setting coordinates is about the most obscure one I have ever seen. - Paul
      reopen a dialog?
      #!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit; $mw->Button( -text => "Button", -command => sub { my $d = $mw->Dialog( -title => "Title", -buttons => [ "OK", "Cance +l" ] ); $d->geometry('200x200+40+40'); warn 'Show ', $d->Show; $d->destroy; undef $d; }, )->pack; $mw->MainLoop; __END__
        Your suggestion is a good one. I have recently been programming in Flash ActionScript and the paradigm is to create a dialog in one place, then open it when needed, close it without disposing, and reopen on subsequent use. When you reopen a dialog, the state is the same as when the user last had it open, which is useful for some dialogs - hence the approach. But in my case, I could have disposed it after all. - Paul
Re: How do I move a top level window in Tk?
by imrags (Monk) on May 13, 2009 at 06:12 UTC
    You can also try Other ways This gives some of the standard options supported by Widgets.
    Raghu