Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e201189

Browse files
fix tcl errors by delaying the widget destruction
1 parent e692b62 commit e201189

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,18 @@ def destroy(self, *args):
431431
if self.canvas._idle_callback:
432432
self.canvas._tkcanvas.after_cancel(self.canvas._idle_callback)
433433

434-
self.window.destroy()
434+
# NOTE: events need to be flushed before issuing destroy (GH #9956),
435+
# however, self.window.update() can break user code. This is the
436+
# safest way to achieve a complete draining of the event queue,
437+
# but it may require users to update() on their own to execute the
438+
# completion in obscure corner cases.
439+
def delayed_destroy():
440+
self.window.destroy()
441+
442+
if self._owns_mainloop and not Gcf.get_num_fig_managers():
443+
self.window.quit()
435444

436-
if self._owns_mainloop and not Gcf.get_num_fig_managers():
437-
self.window.quit()
445+
self.window.after_idle(delayed_destroy)
438446

439447
def get_window_title(self):
440448
return self.window.wm_title()

0 commit comments

Comments
 (0)