]> granicus.if.org Git - python/commitdiff
ttk: fix LabeledScale and OptionMenu destroy() method (#3025)
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 8 Aug 2017 17:41:21 +0000 (19:41 +0200)
committerGitHub <noreply@github.com>
Tue, 8 Aug 2017 17:41:21 +0000 (19:41 +0200)
bpo-31135: Call the parent destroy() method even if the used
attribute doesn't exist.

The LabeledScale.destroy() method now also explicitly clears label
and scale attributes to help the garbage collector to destroy all
widgets.

Lib/tkinter/ttk.py
Misc/NEWS.d/next/Library/2017-08-08-14-44-37.bpo-31135.HH94xR.rst [new file with mode: 0644]

index 3ecc004f0e06f603441a16de3777f248fa4369b4..e1a965e8dff8ab689d967fdc585e2cc2c06d088b 100644 (file)
@@ -1543,11 +1543,12 @@ class LabeledScale(Frame):
         try:
             self._variable.trace_vdelete('w', self.__tracecb)
         except AttributeError:
-            # widget has been destroyed already
             pass
         else:
             del self._variable
-            Frame.destroy(self)
+        super().destroy()
+        self.label = None
+        self.scale = None
 
 
     def _adjust(self, *args):
@@ -1644,5 +1645,8 @@ class OptionMenu(Menubutton):
 
     def destroy(self):
         """Destroy this widget and its associated variable."""
-        del self._variable
-        Menubutton.destroy(self)
+        try:
+            del self._variable
+        except AttributeError:
+            pass
+        super().destroy()
diff --git a/Misc/NEWS.d/next/Library/2017-08-08-14-44-37.bpo-31135.HH94xR.rst b/Misc/NEWS.d/next/Library/2017-08-08-14-44-37.bpo-31135.HH94xR.rst
new file mode 100644 (file)
index 0000000..60068fb
--- /dev/null
@@ -0,0 +1,4 @@
+ttk: fix the destroy() method of LabeledScale and OptionMenu classes.
+Call the parent destroy() method even if the used attribute doesn't
+exist. The LabeledScale.destroy() method now also explicitly clears label and
+scale attributes to help the garbage collector to destroy all widgets.