Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Tk - Place DialogBox in middle of top window

by Dirk80 (Pilgrim)
on Jul 06, 2010 at 09:01 UTC ( [id://848170]=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

Is there a way to place a dialogbox in the middle of the top window?

For example my top window is stored in the variable $mw:

my $db = $mw->DialogBox(-title => "Status", -buttons => ['Cancel']); $db->Show();

Now the problem is that the dialogbox appears anywhere, but not in the middle of the top window.

Thank you for your help

Dirk

Replies are listed 'Best First'.
Re: Tk - Place DialogBox in middle of top window
by herveus (Prior) on Jul 06, 2010 at 11:26 UTC
    Howdy!

    I seem to recall some ways to try to influence where the dialog box appears, but the X window manager can interfere in ways you may have a hard time controlling. Since the dialog box is going to appear in a new top level window, its placement is less under your control.

    yours,
    Michael
Re: Tk - Place DialogBox in middle of top window
by Sinistral (Monsignor) on Jul 06, 2010 at 12:28 UTC

      Hello,

      Thank you for your answer. To get the geometry information via winfo is working fine. So it is no problem to compute the geometry information I need to place the dialogbox in the middle of the main window.

      My problem is how can I set the geometry information to the dialogbox?

      I tried the following code:

      my $db = $mw->DialogBox(-title => "Status", -buttons => ['Cancel'], -geometry => "300x300x+100+100");

      I got this error:

      Tk::Error: Can't set -geometry to `300x300x+100+100' for Tk::DialogBox +=HASH(0x1d85574): unknown option "-geometry" at c:/Perl/site/lib/Tk/C +onfigure.pm line 46. at c:/Perl/site/lib/Tk/Derived.pm line 294

      Thank you for your help.

      Greetings,

      Dirk

Re: Tk - Place DialogBox in middle of top window
by thundergnat (Deacon) on Jul 06, 2010 at 19:20 UTC

    You can't easily affect the geometry of the DialogBox directly since it isn't visible until you Show() it... and doesn't return control until the Show() is done. You CAN pass parameters to the Show() method to affect how it is displayed however. It uses Tk::Popup internally to display. Check the documentation of Popup for details.

    use warnings; use strict; use Tk; use Tk::DialogBox; my $mw = MainWindow->new; my $db = $mw->DialogBox( -title => 'Status', -buttons => ['Ok', 'Cance +l'] ); print $db->Show( -popover => $mw, -overanchor => 'c', -popanchor => ' +c' ); MainLoop;
      This is the perfect hint. Thanks.
Re: Tk - Place DialogBox in middle of top window
by didier (Vicar) on Jul 06, 2010 at 15:19 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://848170]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 06:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found