I've built a simple MVC app that allows the user to manage employee's data. The app contains a couple of single cruds, and it's almost finished. I just need to add some kind of "refresh" function after every add/update/delete employee operation. Currently, I just have to re-run it to see changes. How I may approach the refresh? Inb4. I have done a little research, but most of them are about calling the grid_forget(), and then grid() which is not effective in my case.
Here's what I have tried so far:
def refresh_widgets(self):
for i in self.employee_tree_view_data.get_children():
self.employee_tree_view_data.delete(i)
self.createTreeView()
self.retrieve_employees_data()
def createTreeView(self):
self.employee_tree_view_data.configure(yscrollcommand=self.scrollbar.set)
self.employee_tree_view_data["columns"] = ("name", "surname", "age", "position", "salary")
self.employee_tree_view_data["show"] = "headings"
self.employee_tree_view_data.column("name", width=90, anchor='center')
self.employee_tree_view_data.column("surname", width=90, anchor='center')
self.employee_tree_view_data.column("age", width=90, anchor='center')
self.employee_tree_view_data.column("position", width=90, anchor='center')
self.employee_tree_view_data.column("salary", width=90, anchor='center')
self.employee_tree_view_data.heading("name", text="Name")
self.employee_tree_view_data.heading("surname", text="Surname")
self.employee_tree_view_data.heading("age", text="Age")
self.employee_tree_view_data.heading("position", text="Position")
self.employee_tree_view_data.heading("salary", text="Salary")
# Get index of clicked row and save it as ID to update/delete
self.employee_tree_view_data.bind('<ButtonRelease-1>', lambda e: self.clicked_index())
self.employee_tree_view_data.grid(row=0, column=0, pady=10)
But it instead of delete everything and pass new data, it's just multiplying existing data and adding new one. So if I would have already two rows, it will add these two rows again to the tree view, and then just add the added/edited data. Calling the .update() doesn't change anything at all here. I got stuck here for good, and I'm a bit lack of time.