Jan-30-2024, 09:40 PM
(This post was last modified: Jan-30-2024, 09:40 PM by deanhystad.)
This is hideous.
I would rewrite the code above to look like this:
If you want to erase a tkinter widget from a window, forget it. There is a pack_forget() for removing widgets that were packed, and a grid_forget() for widgets that are in a grid. You can also destroy the widgets if you don't want to use them anymore.
Since you want to remove entire rows, it might make sense to group your controls in widgets in rows, so all the controls for a given row are in a list.
globals()[f"unit_ent{self.count}"] = Entry() globals()[f"unit_ent{self.count}"].grid(row=self.cur_row, column=5) globals()[f"min_lbl{self.count}"] = Label(text="minutes") globals()[f"min_lbl{self.count}"].grid(row=self.cur_row, column=6)Whenever you have variable names that contain index numbers, even if they aren't dynamically generated, you should think "I need to use a list or a dictionary here."
I would rewrite the code above to look like this:
unit_ent.append(tk.Entry()) unit_ent[-1].grid(row=self.cur_row, column=5) min_lbl.append(tk.Label(text="minutes")) min_lbl[-1].grid(row=self.cur_row, column=6)But to address your question.
If you want to erase a tkinter widget from a window, forget it. There is a pack_forget() for removing widgets that were packed, and a grid_forget() for widgets that are in a grid. You can also destroy the widgets if you don't want to use them anymore.
Since you want to remove entire rows, it might make sense to group your controls in widgets in rows, so all the controls for a given row are in a list.