@@ -310,6 +310,14 @@ def _triplet_to_sequence(triplet):
310310 else :
311311 return '<' + _state_names [triplet [0 ]]+ _types [triplet [1 ]][0 ]+ '>'
312312
313+
314+ def _warn_bad_binding (triplet , err ):
315+ # Ignore a key binding invalidated by a typo in the user's config
316+ # instead of crashing IDLE (gh-55646).
317+ print (f'Warning: ignoring invalid key binding '
318+ f'{ _triplet_to_sequence (triplet )!r} : { err } ' , file = sys .stderr )
319+
320+
313321_multicall_dict = {}
314322def MultiCallCreator (widget ):
315323 """Return a MultiCall class which inherits its methods from the
@@ -343,8 +351,15 @@ def bind(self, sequence=None, func=None, add=None):
343351 self .__binders [triplet [1 ]].unbind (triplet , ei [0 ])
344352 ei [0 ] = func
345353 if ei [0 ] is not None :
354+ bad = []
346355 for triplet in ei [1 ]:
347- self .__binders [triplet [1 ]].bind (triplet , func )
356+ try :
357+ self .__binders [triplet [1 ]].bind (triplet , func )
358+ except tkinter .TclError as err :
359+ _warn_bad_binding (triplet , err )
360+ bad .append (triplet )
361+ for triplet in bad : # Drop the invalid sequences.
362+ ei [1 ].remove (triplet )
348363 else :
349364 self .__eventinfo [sequence ] = [func , []]
350365 return widget .bind (self , sequence , func , add )
@@ -374,7 +389,11 @@ def event_add(self, virtual, *sequences):
374389 widget .event_add (self , virtual , seq )
375390 else :
376391 if func is not None :
377- self .__binders [triplet [1 ]].bind (triplet , func )
392+ try :
393+ self .__binders [triplet [1 ]].bind (triplet , func )
394+ except tkinter .TclError as err :
395+ _warn_bad_binding (triplet , err )
396+ continue # Drop the invalid sequence.
378397 triplets .append (triplet )
379398
380399 def event_delete (self , virtual , * sequences ):
0 commit comments