#!/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".
# Get rid of main window, but keep some of it around. $mw->withdraw(); print "Main window created, withdrawn\n";\
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, do 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]
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";Thanks to all.
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]
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.....
perlmonks.org content © perlmonks.org and herby1620, jdtoronto, runrig, Scott7477
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03