diff --git a/Lib/lib-tk/test/test_ttk/support.py b/Lib/lib-tk/test/test_ttk/support.py index c4d842a..6a1c8bf 100644 --- a/Lib/lib-tk/test/test_ttk/support.py +++ b/Lib/lib-tk/test/test_ttk/support.py @@ -1,4 +1,5 @@ import re +import sys import unittest import Tkinter as tkinter @@ -22,6 +23,12 @@ class AbstractTkTest: @classmethod def tearDownClass(cls): cls.root.update_idletasks() + + + widgets = cls.root.grid_slaves() + for widget in widgets: + widget.destroy() + cls.root.destroy() del cls.root tkinter._default_root = None diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py index 3f7ff65..6ce9c65 100644 --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -36,5 +36,12 @@ def test_main(): test_support.run_unittest( *runtktests.get_tests(text=False, packages=['test_ttk'])) + from ttk import Widget + test_support.gc_collect() + if Widget.INSTANCE > 0: + print("leaking %s widgets" % Widget.INSTANCE) + raise Exception("leaking %s widgets" % Widget.INSTANCE) + + if __name__ == '__main__': test_main() diff --git a/Lib/lib-tk/ttk.py b/Lib/lib-tk/ttk.py index 1125439..61f1785 100644 --- a/Lib/lib-tk/ttk.py +++ b/Lib/lib-tk/ttk.py @@ -527,6 +527,7 @@ class Style(object): class Widget(Tkinter.Widget): """Base class for Tk themed widgets.""" + INSTANCE = 0 def __init__(self, master, widgetname, kw=None): """Constructs a Ttk Widget with the parent master. @@ -553,7 +554,10 @@ class Widget(Tkinter.Widget): # Load tile now, if needed _load_tile(master) Tkinter.Widget.__init__(self, master, widgetname, kw=kw) + Widget.INSTANCE += 1 + def __del__(self): + Widget.INSTANCE -= 1 def identify(self, x, y): """Returns the name of the element at position x, y, or the empty