Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Perl/Tk: Dialog boxes for idiots (me)

by herby1620 (Monk)
on May 05, 2006 at 00:36 UTC ( [id://547546]=note: print w/replies, xml ) Need Help??


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

Yes, putting the $mw->withdraw AFTER the $dialog->Show works. But I also get a silly empty window besides the one I want. I used 'messageBox' with the main window "withdrawn" and it works perfectly see: old post (second response). Why not this one with DialogBox. I honestly believe that it CAN be done, what is the missing "secret sauce"?
  • Comment on Re^2: Perl/Tk: Dialog boxes for idiots (me)

Replies are listed 'Best First'.
Re^3: Perl/Tk: Dialog boxes for idiots (me)
by jdtoronto (Prior) on May 05, 2006 at 02:11 UTC
    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

      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".
      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
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://547546]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found