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

Noticed something interesting, and Tk::Dialog is not entirely modal. This is true at least with this combination: windows 7 + strawberry perl 5.12.1 + Tk 804.029

use Tk; use Tk::Dialog; $mw = MainWindow->new(); $mw->Button(-text => "Show", -command => sub {$mw->DialogBox()->Show() +;})->pack; MainLoop();

You click the show button, and a dialog box shows up.

It does initially give you the feeling of a modal dialog. For example, wirth the dialog open, you cannot resize the main window.

However, with the dialog still open, 1) if you click the spacer right under the X button, and drag, the main window actually moves; 2) You can actually click on the X button on the main window, and close the application.

Peter (Guo) Pei

Replies are listed 'Best First'.
Re: Tk:Dialog is not entirely modal
by kcott (Archbishop) on Nov 08, 2010 at 05:49 UTC

    That behaviour seems to be OS-dependent: I can emulate it using Cygwin; I can't emulate it on Windows XP; I don't have access to Windows 7 to try it there.

    In quite a few cases, Tk attempts to retain the look-and-feel of the underlying OS (e.g. window decorations, menus, scrollbars). This may be another of these cases.

    Here's a few things you could try:

    • Do you get the same behaviour when capturing, and acting upon, the return value. E.g. my $db = $mw->DialogBox(); my $retval = $db->Show(); if ($retval eq "X") { do_X(); }
    • Do you get the same behaviour with a global grab, i.e. Show->('-global')
    • Does the workaround involving WM_DELETE_WINDOW suggested by fanticla earlier (tk close window) produce different results.
    • Check if this behaviour occurs in other non-Tk applications on Windows 7.

    -- Ken

      Thanks for testing!

      Quickly share the answers to questions 1 and 4, since I did try:

      DialogBox had the same issue.

      I opened notepad, then opened its "save as" dialog, and could not close notepad with the dialog open - which is obviously the expected behavior of a modal dialog.

      Peter (Guo) Pei

        Thanks for the feedback.

        It occurred to me that one final check you could make would be to see if you get this same behaviour with the widget demo. You can check both Tk::DialogBox and Tk::MsgBox via Common Dialogs - Message boxes. I got the same as I reported above for Cygwin and Windows XP.

        -- Ken

Re: Tk:Dialog is not entirely modal
by aquarium (Curate) on Nov 08, 2010 at 05:33 UTC
    not sure what you're expecting from a modal dialog, but it's normal for you to still be able to move/close/minimize the main application window (with whatever is inside). but in any case, it's difficult to make a non-built-in box truly modal directly in TK or any other language.
    the hardest line to type correctly is: stty erase ^H
      From Wikipedia (emphasis added):
      In user interface design, a modal window is a child window that requires users to interact with it before they can return to operating the parent application, thus preventing the workflow on the application main window.
Re: Tk:Dialog is not entirely modal
by ww (Archbishop) on Nov 08, 2010 at 05:23 UTC
    ...and the question is?

    Perhaps, "has anyone experienced the same with other combinations of OS and Perl and TK versions?" or "Can anyone explain why this happens?"

Re: Tk:Dialog is not entirely modal
by Anonymous Monk on Nov 08, 2010 at 16:05 UTC
    Same perl/tk version as you, but I don't see this on WinXP