I would like to create a lot of widgets in tkinter. I am currently using a lot of code for this. Is there a way to summarise the code? However, I would still like to be able to capture the value of each widgets. The numbering goes up to 200... Thanks a lot!
'''
self.A1_rubbing_marks_Type = tk.StringVar(self.A_Frame_measure)
# Dictionary with options
self.A1_choice_rubbing_marks= ['No', 'Yes']
self.A1_rubbing_marks_Type.set('') # set the default option
self.A1_Menu_rubbing_marks = tk.OptionMenu(self.A_Frame_measure, self.A1_rubbing_marks_Type, *self.A1_choice_rubbing_marks, command=self.show_rubbing_marks_borders)
self.A1_Menu_rubbing_marks.config(width=4)
self.A1_Menu_rubbing_marks.grid_forget()
self.A2_rubbing_marks_Type = tk.StringVar(self.A_Frame_measure)
# Dictionary with options
self.A2_choice_rubbing_marks= ['No', 'Yes']
self.A2_rubbing_marks_Type.set('') # set the default option
self.A2_Menu_rubbing_marks = tk.OptionMenu(self.A_Frame_measure, self.A2_rubbing_marks_Type, *self.A2_choice_rubbing_marks, command=self.show_rubbing_marks_borders)
self.A2_Menu_rubbing_marks.config(width=4)
self.A2_Menu_rubbing_marks.grid_forget()
self.A3_rubbing_marks_Type = tk.StringVar(self.A_Frame_measure)
# Dictionary with options
self.A3_choice_rubbing_marks= ['No', 'Yes']
self.A3_rubbing_marks_Type.set('') # set the default option
self.A3_Menu_rubbing_marks = tk.OptionMenu(self.A_Frame_measure, self.A3_rubbing_marks_Type, *self.A3_choice_rubbing_marks, command=self.show_rubbing_marks_borders)
self.A3_Menu_rubbing_marks.config(width=4)
self.A3_Menu_rubbing_marks.grid_forget()
self.A4_rubbing_marks_Type = tk.StringVar(self.A_Frame_measure)
# Dictionary with options
self.A4_choice_rubbing_marks= ['No', 'Yes']
self.A4_rubbing_marks_Type.set('') # set the default option
self.A4_Menu_rubbing_marks = tk.OptionMenu(self.A_Frame_measure, self.A4_rubbing_marks_Type, *self.A4_choice_rubbing_marks, command=self.show_rubbing_marks_borders)
self.A4_Menu_rubbing_marks.config(width=4)
self.A4_Menu_rubbing_marks.grid_forget()
'''
I defined a dict, but i get too much issues.
'''
keys_blade_exchange_Type = [f"A{i}" for i in range(1, 200)]
self.blade_exchange_Type = {k_2: tk.StringVar(self.A_Frame_measure) for k_2 in keys_blade_exchange_Type}
self.choice_blade_exchange = ['No', 'Yes']
self.Menu_blade_exchange = {k_2: tk.OptionMenu(self.A_Frame_measure, *self.choice_blade_exchange , self.blade_exchange_Type[k_2]) for k_2 in keys_blade_exchange_Type}
for r, (k_2, cb_2) in enumerate(self.Menu_blade_exchange.items(), start=2):
cb_2.grid(row=r, column=1, sticky="W", padx=25, pady=4)
'''
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…