You can do it by taking advantage of the fact that the tkinter grid geometry manager, keeps track of the row and column location of all the widgets under its control. This means you can get the information 0needed from it instead of keeping track of it yourself (in some situations, like this one). You can get the grid information about a particular widget by calling its grid_info()
method.
This illustrates what I am talking about:
from tkinter import *root = Tk()data = [1, 3, 5, 7, 9]for i in range(len(data)): data_label = Label(root, text=data[i]) data_label.grid(row=i+1, column=0)def remove_data_labels(): col = data_label.grid_info()['column'] # Column data_labels are in. # Create list of all the widgets in this same column. widgets = data_label.master.grid_slaves(column=col) # Remove the text from all the Labels in same column. for widget in widgets: if isinstance(widget, Label): widget.config(text='')button = Button(root, text="Remove", command=remove_data_labels)button.grid(row=0, column=1)root.mainloop()