@@ -1458,16 +1458,19 @@ def unbind(self, sequence, funcid=None):
14581458 Otherwise destroy the current binding for SEQUENCE, leaving SEQUENCE
14591459 unbound.
14601460 """
1461+ self ._unbind (('bind' , self ._w , sequence ), funcid )
1462+
1463+ def _unbind (self , what , funcid = None ):
14611464 if funcid is None :
1462- self .tk .call ('bind' , self . _w , sequence , '' )
1465+ self .tk .call (* what , '' )
14631466 else :
1464- lines = self .tk .call ('bind' , self . _w , sequence ).split ('\n ' )
1467+ lines = self .tk .call (what ).split ('\n ' )
14651468 prefix = f'if {{"[{ funcid } '
14661469 keep = '\n ' .join (line for line in lines
14671470 if not line .startswith (prefix ))
14681471 if not keep .strip ():
14691472 keep = ''
1470- self .tk .call ('bind' , self . _w , sequence , keep )
1473+ self .tk .call (* what , keep )
14711474 self .deletecommand (funcid )
14721475
14731476 def bind_all (self , sequence = None , func = None , add = None ):
@@ -1479,7 +1482,7 @@ def bind_all(self, sequence=None, func=None, add=None):
14791482
14801483 def unbind_all (self , sequence ):
14811484 """Unbind for all widgets for event SEQUENCE all functions."""
1482- self .tk . call ( 'bind' , 'all' , sequence , '' )
1485+ self ._root (). _unbind (( 'bind' , 'all' , sequence ) )
14831486
14841487 def bind_class (self , className , sequence = None , func = None , add = None ):
14851488 """Bind to widgets with bindtag CLASSNAME at event
@@ -1494,7 +1497,7 @@ def bind_class(self, className, sequence=None, func=None, add=None):
14941497 def unbind_class (self , className , sequence ):
14951498 """Unbind for all widgets with bindtag CLASSNAME for event SEQUENCE
14961499 all functions."""
1497- self .tk . call ( 'bind' , className , sequence , '' )
1500+ self ._root (). _unbind (( 'bind' , className , sequence ) )
14981501
14991502 def mainloop (self , n = 0 ):
15001503 """Call the mainloop of Tk."""
@@ -2805,9 +2808,7 @@ def bbox(self, *args):
28052808 def tag_unbind (self , tagOrId , sequence , funcid = None ):
28062809 """Unbind for all items with TAGORID for event SEQUENCE the
28072810 function identified with FUNCID."""
2808- self .tk .call (self ._w , 'bind' , tagOrId , sequence , '' )
2809- if funcid :
2810- self .deletecommand (funcid )
2811+ self ._unbind ((self ._w , 'bind' , tagOrId , sequence ), funcid )
28112812
28122813 def tag_bind (self , tagOrId , sequence = None , func = None , add = None ):
28132814 """Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
@@ -3914,9 +3915,7 @@ def tag_add(self, tagName, index1, *args):
39143915 def tag_unbind (self , tagName , sequence , funcid = None ):
39153916 """Unbind for all characters with TAGNAME for event SEQUENCE the
39163917 function identified with FUNCID."""
3917- self .tk .call (self ._w , 'tag' , 'bind' , tagName , sequence , '' )
3918- if funcid :
3919- self .deletecommand (funcid )
3918+ return self ._unbind ((self ._w , 'tag' , 'bind' , tagName , sequence ), funcid )
39203919
39213920 def tag_bind (self , tagName , sequence , func , add = None ):
39223921 """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
@@ -3927,6 +3926,11 @@ def tag_bind(self, tagName, sequence, func, add=None):
39273926 return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
39283927 sequence , func , add )
39293928
3929+ def _tag_bind (self , tagName , sequence = None , func = None , add = None ):
3930+ # For tests only
3931+ return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
3932+ sequence , func , add )
3933+
39303934 def tag_cget (self , tagName , option ):
39313935 """Return the value of OPTION for tag TAGNAME."""
39323936 if option [:1 ] != '-' :
0 commit comments