In one of my projects I used the Tcl window manager attribute '-disabled' onto the parent window, that called a (modal) toplevel dialog window.
Don't know which windows you show with your MFC application are created or used with Tcl stuff, but if your parent window is Tk based you could do this:
In Python simply call onto the parent window inside the creation method of your toplevel window:
MyParentWindow.wm_attributes("-disabled", True)
After you got what you want with your modal window don't forget to use a callback function inside your modal window, to enable inputs on your parent window again! (otherwise you won't be able to interact with your parent window again!):
MyParentWindow.wm_attributes("-disabled", False)
A Tkinter (Tcl Version 8.6) Python example (tested on Windows 10 64bit):
# Python 3+
import tkinter as tk
from tkinter import ttk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.minsize(300, 100)
self.button = ttk.Button(self, text="Call toplevel!", command=self.Create_Toplevel)
self.button.pack(side="top")
def Create_Toplevel(self):
# THE CLUE
self.wm_attributes("-disabled", True)
# Creating the toplevel dialog
self.toplevel_dialog = tk.Toplevel(self)
self.toplevel_dialog.minsize(300, 100)
# Tell the window manager, this is the child widget.
# Interesting, if you want to let the child window
# flash if user clicks onto parent
self.toplevel_dialog.transient(self)
# This is watching the window manager close button
# and uses the same callback function as the other buttons
# (you can use which ever you want, BUT REMEMBER TO ENABLE
# THE PARENT WINDOW AGAIN)
self.toplevel_dialog.protocol("WM_DELETE_WINDOW", self.Close_Toplevel)
self.toplevel_dialog_label = ttk.Label(self.toplevel_dialog, text='Do you want to enable my parent window again?')
self.toplevel_dialog_label.pack(side='top')
self.toplevel_dialog_yes_button = ttk.Button(self.toplevel_dialog, text='Yes', command=self.Close_Toplevel)
self.toplevel_dialog_yes_button.pack(side='left', fill='x', expand=True)
self.toplevel_dialog_no_button = ttk.Button(self.toplevel_dialog, text='No')
self.toplevel_dialog_no_button.pack(side='right', fill='x', expand=True)
def Close_Toplevel(self):
# IMPORTANT!
self.wm_attributes("-disabled", False) # IMPORTANT!
self.toplevel_dialog.destroy()
# Possibly not needed, used to focus parent window again
self.deiconify()
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
For more information about Tcl window manager attributes, just take a look at the Tcl documentation: https://wiki.tcl.tk/9457
w.grab_set()
(or the more impolitew.grab_set_global()
) should do it. Search for "modal" here. – Clavicembalo