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

Hello Monks , I have this dialog box inside my script , the issue I am having is that, I will have to click twice on the YES key on order for that box to save and exit from the screen . why is that?
my $dialog = $mw->DialogBox (-title => "Delete", -buttons => ["Yes", " +No"]); $dialog->Label (-text => "Are You Sure you Want to Save?")->pack (-sid +e => 'left'); return 0 if $dialog->Show eq "No"; save ()and exit if $dialog->Show eq "Yes"; exit; sub save { } ;

Replies are listed 'Best First'.
Re: pl/tk dialog box issue
by kvale (Monsignor) on Mar 04, 2004 at 17:58 UTC
    It looks like you are showing the dialog box twice. Try this instead:
    my $dialog = $mw->DialogBox (-title => "Delete", -buttons => ["Yes", " +No"]); $dialog->Label (-text => "Are You Sure you Want to Save?")->pack (-sid +e => 'left'); my $answer = $dialog->Show; return 0 if $answer eq "No"; save ()and exit if $answer eq "Yes"; exit; sub save { } ;

    -Mark

Re: pl/tk dialog box issue
by jdporter (Paladin) on Mar 04, 2004 at 18:08 UTC
    Remember that calling $dialog->Show pops up the dialog and doesn't return until the user has clicked a button. Well, you're calling that function twice. What you need to do is call it once, and save the result in a variable so you can test it as many times as you need to. Like so:
    my $dialog = $mw->DialogBox (-title => "Delete", -buttons => ["Yes", " +No"]); $dialog->Label (-text => "Are You Sure you Want to Save?")->pack (-sid +e => 'left'); my $result = $dialog->Show; return 0 if $result eq "No"; save() and exit if $result eq "Yes"; exit;

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.