Skip to content

bpo-31135: ttk: fix LabeledScale and OptionMenu destroy() method #3025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Lib/tkinter/ttk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent's destroy() now is called even if this destroy() already was called. I.e. it can be called twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a deliberate choice. All other ttk widgets now have the same behaviour.

self.label = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not del them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike when attributes "disappear". I prefer setting them to None. Moreover, "self.label = None" doesn't fail if destroy() is called twice, whereas "del self._variable" requires a try/except AttributeError.

self.scale = None


def _adjust(self, *args):
Expand Down Expand Up @@ -1644,5 +1645,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()
Original file line number Diff line number Diff line change
@@ -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.