Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the underlying window when a popup is created in Python TKinter

Tags:

python

tkinter

I have a master Frame (call it a), and a popup Toplevel (call it b). How do I make sure the user cannot click on anything in a while b is "alive"?

like image 241
Daniel Kats Avatar asked Mar 12 '13 14:03

Daniel Kats


People also ask

How do you disable a Tk window?

To disable all the widgets inside that particular frame, we have to select all the children widgets that are lying inside that frame using winfor_children() and change the state using state=('disabled' or 'enable') attribute.

How do I hide the root window in Python?

In order to destroy the window we can use the destroy() callable method. However, to hide the Tkinter window, we generally use the “withdraw” method that can be invoked on the root window or the main window. In this example, we have created a text widget and a button “Quit” that will close the root window immediately.

How do I handle the window close event in Tkinter?

To handle the window close event in Tkinter with Python, we call the root. protocol method with the 'WM_DELETE_WINDOW' event. to call root. protocole with "WM_DELETE_WINDOW" to add a close window handler.

How do I create a popup window in Tkinter?

Popup window in Tkinter can be created by defining the Toplevel(win) window. A Toplevel window manages to create a child window along with the parent window. It always opens above all the other windows defined in any application.


1 Answers

If you don't want to hide the root but just make sure the user can only interact with the popup, you can use grab_set() and grab_release().

b.grab_set() # when you show the popup
# do stuff ...
b.grab_release() # to return to normal

Alternatively, you could withdraw() the root to make it invisible:

a.withdraw()

will leave the root alive, but only b visible.

If you need it back, you can do

a.deiconify()
like image 176
Junuxx Avatar answered Oct 17 '22 05:10

Junuxx