From Vasilis.Vlachoudis at cern.ch Thu Feb 13 10:11:12 2020 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Thu, 13 Feb 2020 15:11:12 +0000 Subject: [Tkinter-discuss] Debug mainloop events Message-ID: <0BC70B5D93E054469872FFD0FE07220E02E64AB669@CERNXCHG51.cern.ch> Hi all, is there a way to debug the mainloop events execution. I want to check which functions are causing some delay. The code is too big to run with a profiler and/or add some decorators in every function. What I would like is to have full control of the main loop, replace it with something like while True: event = get_event if event: tstart = time.time() execute event print("time executing event", event, time.time() - tstart) Vasilis From Vasilis.Vlachoudis at cern.ch Fri Feb 14 08:47:45 2020 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 14 Feb 2020 13:47:45 +0000 Subject: [Tkinter-discuss] tk bug in wait_visibility? Message-ID: <0BC70B5D93E054469872FFD0FE07220E02E64ACAE0@CERNXCHG51.cern.ch> 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) From bryan.oakley at gmail.com Fri Feb 14 09:47:50 2020 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Fri, 14 Feb 2020 08:47:50 -0600 Subject: [Tkinter-discuss] tk bug in wait_visibility? In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E02E64ACAE0@CERNXCHG51.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E02E64ACAE0@CERNXCHG51.cern.ch> Message-ID: 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.Vlachoudis at 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 at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: