pashanoid has asked for the wisdom of the Perl Monks concerning the following question:

Dear Elders, this dialog misbehaves, does not listen to me, what should I do?

The prompt changes from 'some error message' to 'we're ok now!' but does not go away entirely. It stays out there with an "ok" button. How do I make it go away altogether? Thank you!

$warnings = ""; $prompt_warning = $mw->Dialog(-title => 'Warings:', -textvariable => \ +$warnings, -bitmap => 'warning' ); $prompt_warning->destroy if ($warnings eq 'we\re ok no +w!'); $answer= &readmap(1069); #reads warings from my invertor for (my $i=1; $i<256; $i=$i*2) { if (($answer&$i)!=0) { $warning = EnWarning{$answer&$i}; $prompt_warning->Show( ); } } if ($answer==0) { $warnings = 'we\'re ok now!'; $prompt_warning->destroy; } }

Replies are listed 'Best First'.
Re: Unable to completely destroy a Dialog in Perl Tk
by Khen1950fx (Canon) on Aug 11, 2011 at 08:40 UTC
    $prompt_warning->destroy if ($warnings eq "we're ok now!"; is premature and doesn't work. It works better by calling "after" right before "show". Here's a dialog that disappears after 10000 milliseconds:
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Dialog; my $mw = MainWindow->new; my $warnings = ""; my $prompt_warning = $mw->Dialog( -title => 'Warnings:', -text => 'danger', -bitmap => 'warning', -default_button => 'OK' ); my $answer = readmap(0); my %question; for ( my $i = 1 ; $i < 256 ; $i = $i * 2 ) { unless ( ( $answer & $i ) == 0 ) { $warnings = $question{$answer}; $prompt_warning->after( 10000, sub { $prompt_warning->Exit; } ); $prompt_warning->Show(); } } sub readmap { print "What is readmap()?\n"; }

      Works like a charm! Thank you!

      readmap() is a subroutine that talkes to a smart invertor and gets all kinds of parameters from it, here's a screenshot: http://www.pashanoid.ru/warning_1.png

Re: Unable to completely destroy a Dialog in Perl Tk
by Anonymous Monk on Aug 11, 2011 at 07:37 UTC

    Dear Elders, this dialog misbehaves, does not listen to me, what should I do?

    Read Coping with Scoping, How do I post a question effectively?, and start posting code that compiles, code like

    #!/usr/bin/perl -- use Tk; use Tk::Dialog; my $mw = tkinit; my $snot = "snot"; $mw->Label( -textvariable => \$snot )->pack;; $mw->Button( -text => 'wipe', -command => sub { my $d = $mw->Dialog( -title => "Title", -text => "Text", -buttons => [ "OK", "Cancel" ] ); $d->geometry('200x200+40+40'); $snot .= '('. $d->Show . ")\n"; $d->destroy(); undef $d; }, )->pack; MainLoop; __END__
      Thank you for going to all this trouble of posting a real 'live' example of a dialog box. This is a trivial example. Mine is more complicated because the internals of my program call out for a creation of a dialog box based on some event inside the program. Then when this event is gone (process killed, message recieve, etc) the dialog box should just dissapear on its own... is this possible? I don't want the user to press OK or CANCEL or anything... Just want the DIALOG gone. If not possible I will not use dialogs at all. Thank you!