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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update __init__.py
Revise docstring to match behavior specified by Serhiy.  Rearrange code to match.
  • Loading branch information
terryjreedy authored Jan 16, 2020
commit 597ef390423d5d143e768d0c044ed6141be75b8e
20 changes: 13 additions & 7 deletions Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,14 +1385,20 @@ 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 the event SEQUENCE. if
FUNCID is given, delete the command also."""
funcs = self.tk.call('bind', self._w, sequence, None)
self.tk.call('bind', self._w, sequence, '')
if funcid:
self.deletecommand(funcid)
keep = '\n'.join(f for f in funcs.split('\n') if not f.startswith(f'if {{"[{funcid}'))
"""Unbind for this widget the event SEQUENCE.

If FUNCID is given, only unbind the function identified with FUNCID.
and also delete that command.
"""
if funcid is None:
self.tk.call('bind', self._w, sequence, None)
else:
funcs = self.tk.call('bind', self._w, sequence, None).split('\n')
keep = '\n'.join(f for f in funcs.split('\n')
if not f.startswith(f'if {{"[{funcid}'))
self.tk.call('bind', self._w, sequence, keep)
self.deletecommand(funcid)


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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy