Skip to content

Commit cd7e9c1

Browse files
authored
ttk: fix LabeledScale and OptionMenu destroy() method (#3025)
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.
1 parent 733d0f6 commit cd7e9c1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Lib/tkinter/ttk.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,12 @@ def destroy(self):
15431543
try:
15441544
self._variable.trace_vdelete('w', self.__tracecb)
15451545
except AttributeError:
1546-
# widget has been destroyed already
15471546
pass
15481547
else:
15491548
del self._variable
1550-
Frame.destroy(self)
1549+
super().destroy()
1550+
self.label = None
1551+
self.scale = None
15511552

15521553

15531554
def _adjust(self, *args):
@@ -1644,5 +1645,8 @@ def set_menu(self, default=None, *values):
16441645

16451646
def destroy(self):
16461647
"""Destroy this widget and its associated variable."""
1647-
del self._variable
1648-
Menubutton.destroy(self)
1648+
try:
1649+
del self._variable
1650+
except AttributeError:
1651+
pass
1652+
super().destroy()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ttk: fix the destroy() method of LabeledScale and OptionMenu classes.
2+
Call the parent destroy() method even if the used attribute doesn't
3+
exist. The LabeledScale.destroy() method now also explicitly clears label and
4+
scale attributes to help the garbage collector to destroy all widgets.

0 commit comments

Comments
 (0)