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

#!/usr/bin/perl #DESCRIPTION DialogBox seems to ignore the positioning portion of the +geometry specification. Is there another way to position the DialogBo +x? #ERROR MESSAGE There isn't one. #PLATFORM Windows XP, SP2, ActiveState's Perl v5.8.7 for Windows use Tk; use Tk::Dialog; use strict; use warnings; my $mw = MainWindow->new; $mw->geometry('400x200+10+10'); $mw->Button ( -text=> 'DialogBox', -command=> sub { for my $i (1..10) { my $db = $mw->DialogBox(-title => 'title', -buttons => ['OK', 'Can +cel'], -default_button => 'Ok'); $mw->geometry(sprintf ("%dx%d+%d+%d", 400-$i*10, 200+$i*10, 10+$i* +10, 10+$i*10 )); $db->geometry(sprintf ("%dx%d+%d+%d", 300+$i*10, 300-$i*10, 30+$i* +10, 30+$i*10 )); $db->Show(); } } )->pack (); MainLoop;

Replies are listed 'Best First'.
Re: TK::Dialogbox geometry spec
by Anonymous Monk on Jul 08, 2008 at 21:53 UTC
    use Tk; use Tk::Dialog; use strict; use warnings; my $mw = MainWindow->new; $mw->geometry('400x200+20+10'); $mw->Button ( -text=> 'DialogBox', -command=> sub { for my $i (1..10) { my $db = $mw->DialogBox(-title => 'title', -buttons => ['OK', 'Can +cel'], -default_button => 'Ok'); $mw->geometry(sprintf ("%dx%d+%d+%d", 400-$i*10, 200+$i*10, 10+$i* +10, 10+$i*10 )); $mw->update(); $db->geometry(sprintf ("%dx%d+%d+%d", 300+$i*10, 300-$i*10, 30+$i* +10, 30+$i*10 )); $db->update(); $db->Show(); } } )->pack (); MainLoop; 1;
    I can't take credit for the solution. It was here at ActiveState's website
      The $widget->update doesn't do the trick. And the link talks about querying the widget for its spec. That's not what I'm trying to do.

      The DialogBox *does* size properly to a by b in the "a*b+c+d".

      The DialogBox does not position properly to "in cx" and "down b" in the "a*b+c+d".

      I'd like to know how to get DialogBox not to ignore (c,d).
Re: TK::Dialogbox geometry spec
by zentara (Cardinal) on Jul 09, 2008 at 11:51 UTC
    If you read "perldoc Tk::Dialog" it states that all positioning is done by the Popup method, read "perldoc Tk::Popup". Popup positions are limited. If you want to move your dialog, you need to roll your own, with a toplevel window. It's not that hard, you just add a global grab.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $tl; my $mw = MainWindow->new; $mw->title( "MainWindow" ); $mw->Button( -text => "Toplevel", -command => \&do_Toplevel )->pack(); MainLoop; sub do_Toplevel { if ( !Exists( $tl ) ) { $tl = $mw->Toplevel(); $tl->geometry('300x100+100+100'); $tl->title( "Toplevel" ); #put all your widgets here $tl->Button( -text => "Close", -command => sub { $tl->grabRelease; $tl->withdraw } )->pack; } else { $tl->deiconify(); $tl->raise(); $tl->grabGlobal; } }

    I'm not really a human, but I play one on earth CandyGram for Mongo
      That's where I was headed. But there are two Dialog-widget-type features I couldn't figure out how to implement. 1) solved by the GRAB you demonstrated (thanks). 2):

      Dialog, messageBox and DialogBox widgets all suspend the routine calling them until the user deals with the popup.

      Toplevel does not. A new (Toplevel) window is spawned and the routine goes on its way.

      I need for the routine to wait until the box is closed and react to the data the user entered.

      Why? I'm looping through an array that points to records data. If a particular record is missing one or more fields, a window pops to ask for it. When it's been entered, the next window pops prompting for missing fields in subsequent records.

      As is, the mainwindow tries to spawn LOTS of windows (one for each record missing any fields) simultaneously (and bombs out).
        If I understand you correctly, you want a dialog type widget that returns some data, rather than an Ok, etc. You might want to look at Tk RGBColorDialog where I use a toplevel as a dialog with a data return value.

        I'm not really a human, but I play one on earth CandyGram for Mongo