CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Perl/Tk: waitVariable doesn't work when multiple Toplevel opened


New User

Nov 8, 2011, 5:51 AM

Post #1 of 1 (1431 views)
Perl/Tk: waitVariable doesn't work when multiple Toplevel opened Can't Post


I'm writing a Perl/Tk script (my first GUI ever) and I have
a problem that looks to me like a very basic misunderstanding
of how things should work in GUI.

The program sometimes opens a warning popup which I
implemented as a "Dialog" widget. It worked as it
should at first - clicking the "OK" button closed the
dialog and the main program continued doing what it warned
me about. But when I added an additional "Toplevel" to the
main window the troubles began: if the warning popup
appeared while the additional "Toplevel" is opened, clicking on
the "OK" button doesn't cause the popup window to close and
in fact, the whole program stops responding to buttons clicks,
scroll sliders and the only thing that works is clicking on
main window/additional "Toplevel"/warning popup brings it
to front.

After googling on multiple "Toplevel"-s and "Dialog" and finding
nothing that helped, I dove into the code of the packages
(, and found in
the function:

sub Wait 
my $cw = shift;
$cw->Callback(-showcommand => $cw);
$cw->grabRelease if Tk::Exists($cw);
$cw->withdraw if Tk::Exists($cw);
$cw->Callback(-command => $cw->{'selected_button'});

I placed some debug prints (sorry for ugly way of debugging)
in various places and found that the code get stuck on:


I also placed debug prints on the value of


itself and saw it changes from "" to "OK" when I click
the "OK" button. It seems I don't understand how the
"waitVariable" works: it looks to me the monitored variable
changes regardless of weather the additional "Toplevel"
is opened or not but the "Dialog" code seems to "miss"
the click if additional "Toplevel" is opened or to respond
to click if no additional "Toplevel"is opened.Here's the
"Dialog" creation code (parts that look relevant to me):

my $gui_mw_wrapper = new MainWindow; 
my $gui_warn_text;
sub gui_warn {
$gui_warn_text = $gui_mw_wrapper -> Dialog( -title=>$title,
-font=>"Times 12 normal",

$dbg_answer = $gui_warn_text -> Show();


and the code creating the additional "Toplevel":

my $gui_src_wrapper_frm_wr; 
sub gui_open_tree {
$gui_src_wrapper_frm_wr = $gui_mw_wrapper -> Toplevel( -title=>"Tree",

At some point I added the argument "global" to the "Show"

      $dbg_answer = $gui_warn_text -> Show("global");

At first I thought it solved the problem - clicking "OK"
caused the "Dialog" to close even while additional "Toplevel"
was opened. But since this caused the "grab" to be
"system global", when a little later this dialog popped together
with some other popup and refused to close, I discovered
(fully according to docs of "global grab") that my entire
desktop is stuck thus I had to open a command line session
in order to kill the script so I prefare not to use "global grab"

What am I missing here? I attempted to google things like
"waitVariable multiple Toplevel" or "waitVariable implementation" or "grab global" or similar things but found
nothing that helped me. The script runs with "-w"
and with "use strict;"

TIA for any help!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives