How to create a modal dialog in tkinter?

grab_set is the proper mechanism for making a window “application modal”. That is, it takes all input from all other windows in the same application (ie: other Tkinter windows in the same process), but it allows you to interact with other applications.

If you want your dialog to be globally modal, use grab_set_global. This will take over all keyboard and mouse input for the entire system. You must be extremely careful when using this because you can easily lock yourself out of your computer if you have have a bug that prevents your app from releasing the grab.

When I have the need to do this, during development I’ll try to write a bulletproof failsafe such as a timer that will release the grab after a fixed amount of time.

Leave a Comment