Skip to content

gh-75666: Fix Misc.unbind behaviour when funcid is given #17954

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
9 changes: 6 additions & 3 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,14 @@ def bind(self, sequence=None, func=None, add=None):
return self._bind(('bind', self._w), sequence, func, add)

def unbind(self, sequence, funcid=None):
"""Unbind for this widget for event SEQUENCE the
function identified with FUNCID."""
self.tk.call('bind', self._w, sequence, '')
"""Unbind for this widget the event SEQUENCE. if
FUNCID is given, delete the command also."""
bound = ''
if funcid:
self.deletecommand(funcid)
funcs = self.tk.call('bind', self._w, sequence, None).split('\n')
bound = '\n'.join([f for f in funcs if not f.startswith(f'if {{"[{funcid}')])
self.tk.call('bind', self._w, sequence, bound)

def bind_all(self, sequence=None, func=None, add=None):
"""Bind to all widgets at an event SEQUENCE a call to function FUNC.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On the tkinter library, the widget.unbind(<Sequence>, funcid) call unbinds all bindings for <Sequence>, while documentation states that when funcid is given all other bindings remains untuched. Apparently this behaviour is not offered by tkinter itself and, in case of non-empty funcid argument value be given, should be obtained by, at first, unbinding all bindings and then bind again all the ones not having the given funcid. This is basically what the proposed patch does. It takes account of the modifications done into the unbind method docstring, as described by other PSF members on the issue tracker.