-2

How can I spawn a window, and halt the execution of the GUI until this window is closed by the user?

Right leg
  • 16,080
  • 7
  • 48
  • 81
AM93
  • 45
  • 7
  • GUIs are always waiting for the user to click or type. Are you asking how to wait until they destroy the window (eg: clicking "OK" or "Dismiss")? – Bryan Oakley Sep 17 '17 at 22:31
  • I guess he is asking for a modal dialog. If this is the case then this is a duplicate of [How to create a modal dialog in tkinter?](https://stackoverflow.com/questions/16803686/how-to-create-a-modal-dialog-in-tkinter) – wp78de Sep 18 '17 at 03:09
  • I was asking for messagebox.showwarning() – AM93 Sep 18 '17 at 10:29

1 Answers1

0

That's exactly what functions from the tkinter.messagebox submodule will do. These will spawn a dialog, and halt the execution until closed.

For instance, the showinfo function will spawn a window with the first parameter as title and the second as message. Until the window is closed, the remaining of the GUI will not be interactable.

Here is an example demonstrating this.

import tkinter as tk
import tkinter.messagebox as tkmb

root = tk.Tk()       
button = tk.Button(
    root,
    text="Spawn a dialog",
    command=lambda: tkmb.showinfo(
        "Information",
        "Please close this window or press OK to continue"))
button.pack()

root.mainloop()

When the button is clicked, a window spawns. As long as this window is open, the button will not be clickable once again.

Right leg
  • 16,080
  • 7
  • 48
  • 81