@@ -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."""
@@ -2806,9 +2809,7 @@ def bbox(self, *args):
28062809 def tag_unbind (self , tagOrId , sequence , funcid = None ):
28072810 """Unbind for all items with TAGORID for event SEQUENCE the
28082811 function identified with FUNCID."""
2809- self .tk .call (self ._w , 'bind' , tagOrId , sequence , '' )
2810- if funcid :
2811- self .deletecommand (funcid )
2812+ self ._unbind ((self ._w , 'bind' , tagOrId , sequence ), funcid )
28122813
28132814 def tag_bind (self , tagOrId , sequence = None , func = None , add = None ):
28142815 """Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
@@ -3915,9 +3916,7 @@ def tag_add(self, tagName, index1, *args):
39153916 def tag_unbind (self , tagName , sequence , funcid = None ):
39163917 """Unbind for all characters with TAGNAME for event SEQUENCE the
39173918 function identified with FUNCID."""
3918- self .tk .call (self ._w , 'tag' , 'bind' , tagName , sequence , '' )
3919- if funcid :
3920- self .deletecommand (funcid )
3919+ return self ._unbind ((self ._w , 'tag' , 'bind' , tagName , sequence ), funcid )
39213920
39223921 def tag_bind (self , tagName , sequence , func , add = None ):
39233922 """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
@@ -3928,6 +3927,11 @@ def tag_bind(self, tagName, sequence, func, add=None):
39283927 return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
39293928 sequence , func , add )
39303929
3930+ def _tag_bind (self , tagName , sequence = None , func = None , add = None ):
3931+ # For tests only
3932+ return self ._bind ((self ._w , 'tag' , 'bind' , tagName ),
3933+ sequence , func , add )
3934+
39313935 def tag_cget (self , tagName , option ):
39323936 """Return the value of OPTION for tag TAGNAME."""
39333937 if option [:1 ] != '-' :
0 commit comments