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_access_measure_calculation = tk.IntVar()
self.A1_access_measure = tk.Checkbutton(self.A_Frame_measure, text="A1", variable=self.A1_access_measure_calculation)
self.A1_access_measure.grid(row =2, column =0, sticky = "W",padx=25, pady=4)
self.A1_access_measure.bind('<ButtonRelease-1>', lambda A1: self.enable_measure_specification("A1"))
self.A2_access_measure_calculation = tk.IntVar()
self.A2_access_measure = tk.Checkbutton(self.A_Frame_measure, text="A2", variable=self.A2_access_measure_calculation)
self.A2_access_measure.grid(row =3, column =0, sticky = "W",padx=25, pady=4)
self.A2_access_measure.bind('<ButtonRelease-1>', lambda A2: self.enable_measure_specification("A2"))
self.A3_access_measure_calculation = tk.IntVar()
self.A3_access_measure = tk.Checkbutton(self.A_Frame_measure, text="A3", variable=self.A3_access_measure_calculation)
self.A3_access_measure.grid(row =4, column =0, sticky = "W",padx=25, pady=4)
self.A3_access_measure.bind('<ButtonRelease-1>', lambda A3: self.enable_measure_specification("A3"))
self.A4_access_measure_calculation = tk.IntVar()
self.A4_access_measure = tk.Checkbutton(self.A_Frame_measure, text="A4", variable=self.A4_access_measure_calculation)
self.A4_access_measure.grid(row =5, column =0, sticky = "W",padx=25, pady=4)
self.A4_access_measure.bind('<ButtonRelease-1>', lambda A4: self.enable_measure_specification("A4"))
self.A5_access_measure_calculation = tk.IntVar()
self.A5_access_measure = tk.Checkbutton(self.A_Frame_measure, text="A5", variable=self.A5_access_measure_calculation)
self.A5_access_measure.grid(row =6, column =0, sticky = "W",padx=25, pady=4)
self.A5_access_measure.bind('<ButtonRelease-1>', lambda A5: self.enable_measure_specification("A5"))
'''
I would also like to summarise the If conditions.
'''
if self.calculations["A1"].get() == 0 and event_measure == "A1":
self.A1_Menu_blade_exchange.grid(row =2, column = 1, padx=3, pady=1, sticky = "W")
self.A1_Menu_rubbing_marks.grid(row =2, column = 2, padx=3, pady=1, sticky = "W")
if self.calculations["A1"].get() == 1 and event_measure == "A1":
self.A1_Menu_blade_exchange.grid_forget()
self.A1_Menu_rubbing_marks.grid_forget()
self.A1_Menu_rubbing_marks_border.grid_forget()
self.A1_blade_exchange_Type.set('')
self.A1_rubbing_marks_Type.set('')
self.A1_rubbing_marks_border_Type.set('')
if self.calculations["A2"].get() == 0 and event_measure == "A2":
self.A2_Menu_blade_exchange.grid(row =3, column = 1, padx=3, pady=1, sticky = "W")
self.A2_Menu_rubbing_marks.grid(row =3, column = 2, padx=3, pady=1, sticky = "W")
if self.calculations["A2"].get() == 1 and event_measure == "A2":
self.A2_Menu_blade_exchange.grid_forget()
self.A2_Menu_rubbing_marks.grid_forget()
self.A2_Menu_rubbing_marks_border.grid_forget()
self.A2_blade_exchange_Type.set('')
self.A2_rubbing_marks_Type.set('')
self.A2_rubbing_marks_border_Type.set('')
'''
question from:
https://stackoverflow.com/questions/65672150/save-syntax-with-loop-in-python-possible