Jan-31-2024, 05:56 PM
(Jan-30-2024, 09:40 PM)deanhystad Wrote: This is hideous.
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.
i tried both grid_forget and forget that you recommended, using the last item in the list but the widgets still dont disappear. i tried googling it and i ended up with the following
self.remove_button.append(Button(text="Remove Entry",command=lambda : self.remove_button(self.count)))
i ended up with a TypeError
Error:TypeError: 'list' object is not callable
what am i doing wrong?