Tkinter How to Create a Popup Message in Python2 min read

Creating the main window: Tk().
Creation of the modal window: Toplevel().

This code creates a simple Tkinter GUI with a main window and a pop-up window. The main window contains a button that opens the pop-up window when clicked.

The main window is created using the Tk class, and the pop-up window is created using the Toplevel class. The Toplevel class is used to create a window that is independent of the main window, but is still a part of the same application.

The pop-up window contains a button that closes the window when clicked. The transient method is used to make the pop-up window a “transient” window, which means that it will stay on top of the main window and cannot be minimized independently. The grab_set method is used to disable interaction with the main window while the pop-up window is open.

Finally, the mainloop function is called on the main window to start the Tkinter event loop and handle events for the main window.

Warning: only one loop mainloop() corresponding to the main window.

The main_window_name.wait_window (popup window_name) method stops the main script until the popup window is closed.

The pop_popup.grab_set () method prevents any interaction with the main window.

Leave a Comment