From bb0490bb1de3afea5c2a7b7e1d2da8579bc507c5 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Tue, 13 Nov 2018 11:59:22 -0500 Subject: [PATCH] Handling closing with an X with multiple windows better --- PySimpleGUI.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 5d872f4e..8ebeda03 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -190,6 +190,7 @@ class MyWindows(): self.NumOpenWindows = 0 self.user_defined_icon = None self.hidden_master_root = None + self.window_being_closed = None def Decrement(self): self.NumOpenWindows -= 1 * (self.NumOpenWindows != 0) # decrement if not 0 @@ -3041,6 +3042,7 @@ class Window: # print('** tkafter cancel failed **') self.TimerCancelled = True if self.RootNeedsDestroying: + print('*** DESTROYING LATE ***') self.TKroot.destroy() _my_windows.Decrement() # if form was closed with X @@ -3057,6 +3059,11 @@ class Window: def ReadNonBlocking(self): if self.TKrootDestroyed: + try: + self.TKroot.quit() + self.TKroot.destroy() + except: + print('DESTROY FAILED') return None, None if not self.Shown: self.Show(non_blocking=True) @@ -3065,8 +3072,12 @@ class Window: except: self.TKrootDestroyed = True _my_windows.Decrement() - # print("read failed") + print("read failed") # return None, None + if self.RootNeedsDestroying: + print('*** DESTROYING LATE ***') + self.TKroot.destroy() + _my_windows.Decrement() return BuildResults(self, False, self) def Finalize(self): @@ -3214,12 +3225,15 @@ class Window: # IT FINALLY WORKED! 29-Oct-2018 was the first time this damned thing got called def OnClosingCallback(self): + global _my_windows if self.DisableClose: return + _my_windows.window_being_closed = self # print('Got closing callback') - self.TKroot.quit() # kick the users out of the mainloop if self.CurrentlyRunningMainloop: # quit if this is the current mainloop, otherwise don't quit! + self.TKroot.quit() # kick the users out of the mainloop self.TKroot.destroy() # kick the users out of the mainloop + self.RootNeedsDestroying = True else: self.RootNeedsDestroying = True self.TKrootDestroyed = True