diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index 6198c4c..76a4dea 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -1866,6 +1866,9 @@ class Tk(Misc, Wm): global _default_root if _support_default_root and _default_root is self: _default_root = None + if self.children: + raise Exception("destroy() doesn't clear all children: %s" + % self.children) def readprofile(self, baseName, className): """Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if diff --git a/Lib/lib-tk/ttk.py b/Lib/lib-tk/ttk.py index 1125439..b18f2d1 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 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()