in reply to clsoing sub window upon execution?

This can be made much simpler, by using Tk::Dialog.

use Tk; use Tk::Dialog; use strict; use warnings; my $top = new MainWindow(-title => "demo"); my $save = $top->Button(-text => "Close", command => \&process_save)-> +pack(); MainLoop; sub process_save { my $dialog = $top->Dialog(-title => "Save?", -text => "Content ch +anged, save the changes?", -buttons => ["OK", "Cancel"]);#in real wor +ld, you only display this, if the content changed my $response = $dialog->Show(); print $response, "\n" #in real code, handle the response... }

Replies are listed 'Best First'.
Re: Re: clsoing sub window upon execution?
by Elijah (Hermit) on Dec 04, 2003 at 05:13 UTC
    I am not sure dialog will work for this. I need to be able to have a blank text field to enter in a line number and then perform the scroll function. It does not appear that a dialog box allows for text insertion. Am I wrong in thinking this way? If so how would I accomplish this. I read the docs on the module and saw no option for this functionality.

      If that's what you want, then go with Tk::DialogBox, which allows you to add sub-widget. Here is a piece of demo:

      use Tk; use Tk::DialogBox; use strict; use warnings; my $top = new MainWindow(-title => "demo"); my $save = $top->Button(-text => "Goto line", command => \&process_sav +e)->pack(); my $line_num; MainLoop; sub process_save { my $dialog = $top->DialogBox(-title => "Save?", -buttons => ["OK", + "Cancel"]); $dialog->add("Entry", -text => \$line_num)->pack(); my $response = $dialog->Show(); print "[$response, $line_num]\n" #in real code, handle the respons +e... }
        Ok cool. One thing though. What is the syntax to have the script perform it's function when the button in the dialogbox is pressed? Right now as I have it the script performs the function whenever I press the button that calls the dialogbox and not after I enter a line number and pree "Go". Here is the code.
        sub go_to { my $sw = $mw->DialogBox(-title => "Go To Line", -buttons => ["Go"]) +; $sw->add("Entry", -text => \$line_number)->pack(); my $response = $sw->Show(&scroll_line); sub scroll_line { $line_number = $line_number - 1; my $calc = $line_number/$line_count; $t->yviewMoveto($calc); $line_number = $line_number + 1; } }
        I just need "$response" to be executed when the Go button is pressed.