wait_visibility waits for a *change in the visibility,* it doesn't just
wait for the window to be visible. If it's already visible, wait_visibility
will wait for it to be invisible. The geometry method doesn't affect the
visibility state (unless you move the window off-screen perhaps) which is
why your code ends up waiting forever.

If you want to wait for a window to be visible, you should first check to
see if it is already visible. Otherwise you'll end up waiting for it to
become invisible.

On Fri, Feb 14, 2020 at 7:48 AM Vasilis Vlachoudis <
vasilis.vlachou...@cern.ch> wrote:

> 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
>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to