ttk: fix LabeledScale and OptionMenu destroy() method (#3025) (#3030)
![](https://secure.gravatar.com/avatar/cc7737cd64a84f1b5c61a160798e97ee.jpg?s=120&d=mm&r=g)
https://github.com/python/cpython/commit/33460fa7e0bd126bee739a66e1228665dc2... commit: 33460fa7e0bd126bee739a66e1228665dc22e70f branch: 3.6 author: Victor Stinner <victor.stinner@gmail.com> committer: GitHub <noreply@github.com> date: 2017-08-09T10:48:11+02:00 summary: ttk: fix LabeledScale and OptionMenu destroy() method (#3025) (#3030) 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. (cherry picked from commit cd7e9c1b67d3d07ee03e0a79af2791c19031cecb) files: A Misc/NEWS.d/next/Library/2017-08-08-14-44-37.bpo-31135.HH94xR.rst M Lib/tkinter/ttk.py diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py index 9cd0c2073a9..2a3e1cec701 100644 --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -1543,11 +1543,12 @@ def destroy(self): 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): @@ -1647,5 +1648,8 @@ def set_menu(self, default=None, *values): 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 index 00000000000..60068fb648f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-08-08-14-44-37.bpo-31135.HH94xR.rst @@ -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.
participants (1)
-
Victor Stinner