Is wait_window() required for creating a modal dialog in Python Tkinter?
Question: I try to create a modal dialog using Python Tkinter. I found no difference
between using and not using wait_window().

    
    
    import tkinter as tk
    
    def button_click():
      dlg = tk.Toplevel(master=window)
    
      tk.Button(dlg, text="Dismiss", command=dlg.destroy).pack()
    
      dlg.transient(window)    # only one window in the task bar
      dlg.grab_set()           # modal
      #window.wait_window(dlg) # why?
    
    window = tk.Tk()
    
    tk.Button(window, text="Click Me", command=button_click).pack()
    
    window.mainloop()
    

I've seen some examples in that use wait_window() for creating a modal dialog.
So I'm not sure whether the function is required for creating a modal dialog.

I'm using Python 3.5.


Answer: running your code using `window.wait_window(dlg)` won't change anything as
`dlg.grab_set()` already creates a modal dialog. this does only mean that you
cannot close `window` while `dlg` is still alive. you cannot close window as
the modal dialog grabs all mouse events from `window` and redirects them to
`null`.

If you want to create a modal dialog without `grab_set()`, you would need to
bind all mouse events to one handler and then decide if they should be allowed
or dismissed **and** use `wait_window`.

As a modal dialog is defined by _"is anything outside the dialog**and** in my
application available to be clicked"_ == _False_ , you already have a modal
dialog only using `grab_set()`.

If your application shall not be able to programatically close `window`, you
would need `wait_window()` as well.

Hope I made everything clear.

