@@ -2579,26 +2579,31 @@ def font_event(self, font_selected: str) -> None:
25792579 None: No value is returned
25802580 Processing Logic:
25812581 - Sets the internal font attribute to the selected font
2582- - Destroys any existing font label to update it
2583- - Creates a new label displaying the selected font
2584- - Places the label in the GUI
2582+ - Creates or updates the font label.
25852583 - Displays a message box confirming the font change
25862584 """
25872585 the_view = self .parent
25882586 the_view .font = font_selected
2589- with contextlib .suppress (Exception ):
2590- the_view .font_out_label .destroy ()
2591- text = translate_string ("Monospaced Font To Use" )
2592- the_view .font_out_label = customtkinter .CTkLabel (
2593- master = the_view ,
2594- text = f"{ text } : { font_selected } " ,
2595- anchor = "sw" ,
2596- font = (font_selected , 14 ),
2597- )
2598- the_view .font_out_label .grid (row = 6 , column = 1 , padx = 10 , pady = 10 , sticky = "nw" )
2587+
2588+ # Prepare translated text
2589+ font_use_text = translate_string ("Monospaced Font To Use" )
2590+ label_text = f"{ font_use_text } : { font_selected } "
2591+
2592+ # Update or create the label to avoid destroying/recreating it
2593+ if hasattr (the_view , "font_out_label" ) and the_view .font_out_label .winfo_exists ():
2594+ the_view .font_out_label .configure (text = label_text , font = (font_selected , 14 ))
2595+ else :
2596+ the_view .font_out_label = customtkinter .CTkLabel (
2597+ master = the_view ,
2598+ text = label_text ,
2599+ anchor = "sw" ,
2600+ font = (font_selected , 14 ),
2601+ )
2602+ the_view .font_out_label .grid (row = 6 , column = 1 , padx = 10 , pady = 10 , sticky = "nw" )
2603+
25992604 the_view .font_optionmenu .set (font_selected )
2600- text = translate_string ("Font To Use set to" )
2601- the_view .display_message_box (f"{ text } { font_selected } " , "Green" )
2605+ set_to_text = translate_string ("Font To Use set to" )
2606+ the_view .display_message_box (f"{ set_to_text } { font_selected } " , "Green" )
26022607
26032608 # Process the Display Detail Level selection
26042609 def detail_selected_event (self , display_detail : str ) -> None :
0 commit comments