In my tkinter project I've created an Entry, a Label and two Buttons for each of the line in my line list using a for
loop. I've also saved them in a list when created.
Right now my problem is how can I access them? For example: if the edit button of the 12th line is clicked, then I want to be able to get the entry values of the 12th entry or if my user click the delete button of the 3rd line in the list, then, only the entry, the label and the two button of the selected line should be deleted.
This is my code:
self.line_loop = []
for line in self.line_list:
self.row_count += 1
self.n_entry = tk.Entry(self.list_frame, justify="center", width=4)
self.n_entry.grid(row=self.row_count, column=0, pady=10, padx=10, ipady=3)
self.text_label = tk.Label(self.list_frame, text=line, anchor="w", justify="left",
wraplengt=701)
self.text_label.grid(row=self.row_count, column=1, pady=10, padx=10, sticky="w")
self.edit_button = tk.Button(self.list_frame, text="Edit", command=self.edit)
self.edit_button.grid(row=self.row_count, column=2, pady=10, padx=10)
self.delete_button = tk.Button(self.list_frame, text="Delete", command=self.edit)
self.delete_button.grid(row=self.row_count, column=3, pady=10, padx=10)
self.line_loop.append(self.n_entry)
self.line_loop.append(self.text_label)
self.line_loop.append(self.edit_button)
self.line_loop.append(self.delete_button)
EDIT: This are examples of the functions. The code should work only on the clicked button and linked widgets
def delete(self):
self.n_entry.destroy()
self.text_label.destroy()
self.edit_button.destroy()
self.delete_button.destroy()
def edit(self):
for entry in self.line_loop:
print(entry.get())
How can I do so?