in reply to tk close window

Well, there's no X button.

The Ok button throws an exception: Undefined subroutine &main::do_something called ....

The Quit button closes the Dialog window.

Did you think the Quit button shut down the entire application? It doesn't.

Here's an Exit button you can add:

$mw->Button(-text => 'Exit', -command => sub { exit })->pack();

I added that just before my $answer = ... and successfully tested it.

-- Ken

Replies are listed 'Best First'.
Re^2: tk close window
by fanticla (Scribe) on Nov 07, 2010 at 11:01 UTC

    Sorry Ken, I express myself wrongly. With X button I mean the (OS Windows)button you see on the top left of the window(togheter with minimize and risize)

      You start a Tk::Dialog before you enter MainLoop with $dialog_setup->Show().

      Show() has two modes: local grab and global grab. Without arguments, as you've used, the mode is local grab.

      With a local grab, the widget which is the parent of the Dialog ($mw in this case) is effectively frozen - you need to close the Dialog widget before you can perform any operations on the parent. It's normal to start a Dialog after you enter the MainLoop (e.g. Menu-Help-About typically shows "About" information in a Dialog or similar widget).

      In a couple of my tests (on Windows XP and Cygwin), the Dialog was minimised and the "frozen" main window was displayed - I suspect this might have been the behaviour you were seeing. I haven't seen that before but I've always started Dialogs after the MainLoop has been entered. Take a look at the widget demo (Common Dialogs - Message boxes) on your system to check how it "normally" operates.

      -- Ken