Re: making tkFileDialog and tkMessageBox modal on Win32

Andrew Zane <[email protected]>
Newsgroups gmane.comp.python.tkinter
Message-ID <[email protected]>
I had to add a little bit to make the dialog modal to the parent. So anyway, here’s to helping! : )
My comments are prefaced with an #A:, and my modifications are surrounded by the #A tag, #A - #/A, that is.

def tk_wrapgrab(tk, f, kw):
    #retrieved from: http://grokbase.com/t/python/tkinter-discuss/05468hr5qs/making-tkfiledialog-and-tkmessagebox-modal-on-win32
        # Wrap a dialog in a grab pair.
        # Use to make tkFileDialog and tkMessageBox application-modal.
        # Not needed for tkSimpleDialog.
        # tk - grab target, this is what will wait for the tkDialog to close
        # f - tkFileDialog.askopenfilename, tkMessageBox.showinfo, etc.
        # kw - dictionary of key-word arguments to f
    kw['parent'] = tk #A: No need to specify parent then. Grab target here is synonomous to parent.
    tk.grab_set() #A: Grab parent, making parent the only active window (of application) while tkDialog is open.
    retval = f(**kw)
    #A
    tk.wait_variable(retval) #A: Parent wait for the variable, disabling parent until tkDialog returns. Thus, tkDialogs are application-modal.
                             #      If we did a global grab, the tkDialog would be globally-modal.
    #/A
    tk.grab_release()
    return retval
_______________________________________________
Tkinter-discuss mailing list
[email protected]
https://mail.python.org/mailman/listinfo/tkinter-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.