@@ -1537,16 +1537,19 @@ def unbind(self, sequence, funcid=None):
15371537 Otherwise destroy the current binding for SEQUENCE, leaving SEQUENCE
15381538 unbound.
15391539 """
1540+ self ._unbind (('bind' , self ._w , sequence ), funcid )
1541+
1542+ def _unbind (self , what , funcid = None ):
15401543 if funcid is None :
1541- self .tk .call ('bind' , self . _w , sequence , '' )
1544+ self .tk .call (* what , '' )
15421545 else :
1543- lines = self .tk .call ('bind' , self . _w , sequence ).split ('\n ' )
1546+ lines = self .tk .call (what ).split ('\n ' )
15441547 prefix = f'if {{"[{ funcid } '
15451548 keep = '\n ' .join (line for line in lines
15461549 if not line .startswith (prefix ))
15471550 if not keep .strip ():
15481551 keep = ''
1549- self .tk .call ('bind' , self . _w , sequence , keep )
1552+ self .tk .call (* what , keep )
15501553 self .deletecommand (funcid )
15511554
15521555 def bind_all (self , sequence = None , func = None , add = None ):
@@ -1558,7 +1561,7 @@ def bind_all(self, sequence=None, func=None, add=None):
15581561
15591562 def unbind_all (self , sequence ):
15601563 """Unbind for all widgets for event SEQUENCE all functions."""
1561- self .tk . call ( 'bind' , 'all' , sequence , '' )
1564+ self ._root (). _unbind (( 'bind' , 'all' , sequence ) )
15621565
15631566 def bind_class (self , className , sequence = None , func = None , add = None ):
15641567 """Bind to widgets with bindtag CLASSNAME at event
@@ -1573,7 +1576,7 @@ def bind_class(self, className, sequence=None, func=None, add=None):
15731576 def unbind_class (self , className , sequence ):
15741577 """Unbind for all widgets with bindtag CLASSNAME for event SEQUENCE
15751578 all functions."""
1576- self .tk . call ( 'bind' , className , sequence , '' )
1579+ self ._root (). _unbind (( 'bind' , className , sequence ) )
15771580
15781581 def mainloop (self , n = 0 ):
15791582 """Call the mainloop of Tk."""
@@ -2885,9 +2888,7 @@ def bbox(self, *args):
28852888 def tag_unbind (self , tagOrId , sequence , funcid = None ):
28862889 """Unbind for all items with TAGORID for event SEQUENCE the
28872890 function identified with FUNCID."""
2888- self .tk .call (self ._w , 'bind' , tagOrId , sequence , '' )
2889- if funcid :
2890- self .deletecommand (funcid )
2891+ self ._unbind ((self ._w , 'bind' , tagOrId , sequence ), funcid )
28912892
28922893 def tag_bind (self , tagOrId , sequence = None , func = None , add = None ):
28932894 """Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
@@ -3997,9 +3998,7 @@ def tag_add(self, tagName, index1, *args):
39973998 def tag_unbind (self , tagName , sequence , funcid = None ):
39983999 """Unbind for all characters with TAGNAME for event SEQUENCE the
39994000 function identified with FUNCID."""
4000- self .tk .call (self ._w , 'tag' , 'bind' , tagName , sequence , '' )
4001- if funcid :
4002- self .deletecommand (funcid )
4001+ return self ._unbind ((self ._w , 'tag' , 'bind' , tagName , sequence ), funcid )
40034002
40044003 def tag_bind (self , tagName , sequence , func , add = None ):
40054004 """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
@@ -4010,6 +4009,11 @@ def tag_bind(self, tagName, sequence, func, add=None):
40104009 return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
40114010 sequence , func , add )
40124011
4012+ def _tag_bind (self , tagName , sequence = None , func = None , add = None ):
4013+ # For tests only
4014+ return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
4015+ sequence , func , add )
4016+
40134017 def tag_cget (self , tagName , option ):
40144018 """Return the value of OPTION for tag TAGNAME."""
40154019 if option [:1 ] != '-' :
0 commit comments