In some dialogs I wanted to restore the size from the last time it was opened
therefore, before calling the wait_window I have

self.wait_visibility()
self.geometry(...restore...)     #<<< the geometry setting will not work if it 
is not visible
self.wait_window()

If something happens during the filling of the dialog information I show a 
messagebox.
The messagebox is triggering the event loop, which displays also the dialog
If the dialog is displayed then the execution gets stuck in the  
"wait_visibility", 
and when the user closes the dialog, the execution proceeds to the wait_window
which causes an exception since the window do not longer exits.

I think it is a tk bug, that the wait_visibility waits despite the window is 
visible.
The only way to cure it is to add a check "if self.winfo_ismapped()"

Example:


import tkinter as tk
import tkinter.messagebox as messagebox

error = True

class Dialog(tk.Toplevel):
        width  = 320
        height = 240

        def __init__(self, master, *args):
                super().__init__(master, *args)
                self.transient(master)

                self.b = tk.Button(self, text="Close", command=self.close)
                self.b.pack()

                if error:
                        messagebox.showerror("Error",
                                "Something happened",
                                parent=self)

                #if not self.winfo_ismapped(): self.wait_visibility()
                self.wait_visibility()
                if Dialog.width>0:
                        self.geometry(f"{Dialog.width}x{Dialog.height}")
                self.wait_window()

        def close(self):
                # save size... and destroy...
                self.destroy()


root = tk.Tk()
dlg = Dialog(root)
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to