This is a snippet to create a modal window (not just a Tk::Dialog or Tk::DialogBox) using Tk. I'm posting it because I couldn't find a concise way to do this anywhere, on PerlMonks, in the Tk documentation, or on the web. When you use this code, make sure you bind your 'ok' button (or whatever you use) so that it destroy()s the window. None of the buttons normally displayed in the titlebar will be available.
$tl = $main_window->Toplevel( -title => 'Modal Dialog' ); $tl->resizable( 0, 0 ); $tl->transient($tl->Parent->toplevel); $tl->protocol('WM_DELETE_WINDOW' => sub {}); $tl->grab;

Replies are listed 'Best First'.
Re: Tk Modal Window
by Anonymous Monk on Oct 23, 2002 at 14:29 UTC
    Just a quick question:
    I have done this very same thing before. However occasionally I have wanted a dialog window that has the title bar close button but not the minimise or maximise buttons or some combination of buttons :) I have yet to be able to come up with a way to do this using Tk, to my frustration. I know it must be possible, just look at the Tk File Save dialog, if I remember rightly this has just the close button. However having waded through that module code I still came up empty handed.
    Ah well, I am currently learning the Visual C++ MFC which should let me do what I want, but that means no more PERL-Tk :( and too much writing of inane C++ code. Let me know if you find a way at cgjr100@hotmail.com
    Thanks Chris :)