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

Perl/Tk: Dialog boxes for idiots (me)

by herby1620 (Monk)
on May 04, 2006 at 22:32 UTC ( #547534=perlquestion: print w/ replies, xml ) Need Help??
herby1620 has asked for the wisdom of the Perl Monks concerning the following question:

In a previous message I asked about exiting from 'MainLoop', and got a couple of answers. One included exactly what I needed for one instance (Message Box). Now I'm trying to pop up a box (Yes, this is W-XP [yuck!]) and have a couple of selections to pick from. I thought I would use a dialog box, and I'm trying this simple code:
#!/bin/perl -w # Try to get a simple dialog box to work. use Tk; # Bring in the Tk stuff. use Tk::DialogBox; my $mw = MainWindow->new; # Get rid of main window, but keep some of it around. $mw->withdraw(); print "Main window created, withdrawn\n"; 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"; # Done
The problem is that the above example when run on WXP hangs at the ->Show() statement. From what I can tell, the execution focus is somewhere else (it goes away from my command window) and it may be displaying something "invisable". Since it isn't displayed, I can't do anything, and it hangs. To exit, I type ^C and the interrupt kills the script. Can this be made to work? I was very able to get the messageBox to function WITHOUT going into 'MainLoop', can I do something similar here???

Your wisdom would be quite helpful. Past incantations of wisdom have been MOST helpful!! Thanks!!

Update:

It seems that the dialog box is tightly linked to the parent window. They can't (with the code above) be seperated. Even if I try to 'deiconify' the dialog box, until the main window becomes 'normal' it won't happen! Somehow 'messageBox' is able to disconnect these, but THAT is buried pretty deeply in the Tk library (I tried to look for how without luck). Still looking for "secret sauce".

Comment on Perl/Tk: Dialog boxes for idiots (me)
Download Code
Re: Perl/Tk: Dialog boxes for idiots (me)
by Scott7477 (Chaplain) on May 04, 2006 at 23:11 UTC
    If you move the following lines of code:

    # Get rid of main window, but keep some of it around. $mw->withdraw(); print "Main window created, withdrawn\n";\


    down to the last line before your "#Done" comment, the script works.
      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"?
        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

Re: Perl/Tk: Dialog boxes for idiots (me)
by ocroquette (Novice) on Feb 19, 2009 at 16:05 UTC
    I found the secret sauce :) Call:
    $dialog->transient(undef);
    before you call Show(); Enjoy !

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://547534]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-09-17 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls