diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 15945b8bb64..06843c630a2 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -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.