It's a bit hard to understand what you are trying to accomplish since you didn't provide a complete example. If we can assume that each block of code is identical and the only thing that is changing is the index into the array, you might be able to replace all of the if
statements with a single block of code:
if self.calculations[event_measure].get() == 0:
self.Menu_blade_exchange[event_measure].grid(row =2, column = 1, padx=3, pady=1, sticky = "W")
self.Menu_rubbing_marks[event_measure].grid(row =2, column = 2, padx=3, pady=1, sticky = "W")
else:
self.Menu_blade_exchange[event_measure].grid_forget()
self.Menu_rubbing_marks[event_measure].grid_forget()
self.Menu_rubbing_marks_border[event_measure].grid_forget()
self.blade_exchange_Type[event_measure].set('')
self.rubbing_marks_Type[event_measure].set('')
self.rubbing_marks_border_Type[event_measure].set('')
In the comments someone pointed out that the row numbers change, which could be solved by saving the row numbers in an array as well
rownum = {"A1": 2, "A2": 3, ...}
...
if self.calculations[event_measure].get() == 0:
self.Menu_blade_exchange[event_measure].grid(row =rownum[event_measure], column = 1, padx=3, pady=1, sticky = "W")
self.Menu_rubbing_marks[event_measure].grid(row =rownum[event_measure], column = 2, padx=3, pady=1, sticky = "W")
Another solution might be to use grid_remove
rather than grid_forget
, so that all of the configuration options are remembered.
This would likely be much, much easier if each "event measure" was an instance of a class.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…