in reply to Re^2: Perl/Tk: Dialog boxes for idiots (me)
in thread Perl/Tk: Dialog boxes for idiots (me)

No secret sauce, you are attempting to use a Show method on a sub-widget (the DialogBox) belonging to a parent widget which is withdrawn and thus invisible. If the parent is invisible the children cannot Show either.

The exception to this is the MessageBox (well, in my rotten recollection!) where you can do this:

my $mw = MainWindow->new(); $mw->withdraw(); my $ftp_warn = $mw->messageBox( -title => 'Downloading upgrade', -message => "We are about to download an upgrade to your software, d +o you wish to continue?", -type => 'YesNo', -icon => 'question', ); if ( $ftp_warn eq 'No' ) { exit; } else { &doUpdate(); }
This is a fragment fomr something that happens to be open in my editor, but it will illustrate what you need yo do. Again, "Mastering Perl/Tk" is your friend, why not go to http://safari.oreilly.com and get the 14 day free trial. That way you can learn Perl/Tk BEFORE you can get to the bookstore.

jdtoronto

Replies are listed 'Best First'.
Re^4: Perl/Tk: Dialog boxes for idiots (me)
by Scott7477 (Chaplain) on May 05, 2006 at 05:05 UTC
    I reworked your original code in this fashion:

    use strict; use warnings; use Tk; use Tk::DialogBox; my $mw = MainWindow->new; my $dialog = $mw->DialogBox ( -title => "Please pick one of the three", -buttons => ["One", "Two", "Three"]); my $item = $dialog->Show(); print "Returned from the show, got $item\n";


    This runs in the same fashion as your original code sans the one print statement. After scrutinizing the Tk and Tk::Dialog docs on CPAN, I believe I have the answer here.

    From the docs for Tk::Dialog: "A Dialog object essentially consists of two subwidgets: a Label widget for the bitmap and a Label wigdet for the text of the dialog. If required, you can invoke the `configure' method to change any characteristic of these subwidgets."

    You'll notice that the "silly box" that you refer to contains whatever you named this script in the title bar and the rest is blank. I believe that the "silly box" is in fact the Label widget for the bitmap. If so, then there is no way to not display that and display a dialog box using the Tk::Dialog module.

    If someone shows that my surmise is incorrect, I'll be happy to retract this.

    Update 5-05-06: Fixed a typo in the fifth line of code; I had "tmy" instead of "my".
Re^4: Perl/Tk: Dialog boxes for idiots (me)
by herby1620 (Monk) on May 05, 2006 at 16:30 UTC
    Yes, it seems as though MessageBox is the exception. As you show, one can have the main window 'withdrawn' and the message box appears. Obviously there is some flag that allows this (or am I assuming something here?). All I'm asking is that the dialog box have the same ability. I'm willing to "manually" set the proper flag (if possible) for Dialog. At the moment I've resorted to making the main window small and in one of the corners (it has nothing in it). Maybe all of this is buried deep inside Tk and it can't be changed from the Perl prespective. While I do remain hopeful, I have a solution that works for me.

    Thanks to all.

      Well, you can iconise the MainWindow, or in Tk speak - iconify.

      Although I don't have the documentation handy, the MainWindow is merely a special case of a "Toplevel" widget. Special in that it is displayed automatically when you call MainLoop. It is displayed automatically, but every other "Toplevel" must be spcifically placed using one or another of the geometry managers. Thus having created your MainWindow you should then be able to call the iconfy method:

      $mw->iconify();
      and have the pesky window disappear. To get it back?
      $mw->deiconify();

      However it may not reappear on the top of the other windows, to ensure this use the raise method:

      $mw->raise();
      jdtoronto
        Ah, yes, iconify, I know him well. Well, I tried that and while it nicely DOES iconify the main window, the Dialog box is iconified as well. Sorry about that. I thought it was a good idea as well.

        The "find the flag" idea based on the fact that messageBox is related to Dialog is good as well. An exercise for all.

        Why am I doing all of this? I'm running a script that is called by another (seperate Perl invocation) to do some tasks. I thought that having things like 'alert boxes' and 'dialog boxes' (admitally modal things) would be something desirable. So here I am. And so it goes.....

      Well, MessageBox is derived from Dialog, as is DialogBox. So there must be some way of doing it, but I don't think it is a simple 'find the flag' exercise. This thread has been inetersting because I have never had a situation where I wanted a DialogBox without the MainWindow.

      jdtoronto

      Use the source, Luke! ( Look at the source to MessageBox() in Tk.pm ). It seems to just use Tk::Dialog. It shouldn't be too hard to figure out what the secret is to getting the results you want.
        Did anyone find what messageBox's secret ingredient is ? I have been looking and making experiences for quite some time without finding anything :(