Update __init__.py

Revise docstring to match behavior specified by Serhiy.  Rearrange code to match.
This commit is contained in:
Terry Jan Reedy 2020-01-16 15:31:25 -05:00 committed by GitHub
parent 05836401ac
commit 597ef39042
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions

View File

@ -1385,14 +1385,20 @@ class Misc:
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.