diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index a3378d012fb41a..8e221c7d6d74f0 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1385,10 +1385,18 @@ 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, '') - 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, '') + else: + funcs = self.tk.call('bind', self._w, sequence, None).split('\n') + keep = '\n'.join(f for f in funcs + 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): diff --git a/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst new file mode 100644 index 00000000000000..b23b70e616257f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-11-22-09-29.bpo-31485.DSvjsY.rst @@ -0,0 +1 @@ +https://github.com/python/cpython/pull/17954#