How to refresh the contents within the Python TKINTER Tab?
Try to fetch the values again and then insert the new values after deleting the existing values, like:
def refresh_clicked(self): command = """SELECT et.`Equipment Type`, COUNT(i.`Equipment Type`) Total, SUM(IF(`Status`='Unavailable',1,0)) Unavailable, SUM(IF(`Status`='Available',1,0)) Available FROM `Equipment Types` et LEFT JOIN Inventory i ON et.`Equipment Type` = i.`Equipment Type` GROUP BY 1 ORDER BY 1""" mycursor.execute(command) display = mycursor.fetchall() self.tree.delete(*self.tree.get_children()) # Delete all times inside the treeview for row in display: self.tree.insert('','end',value=row) # Insert newly fetched values
Note that I used self.tree
, so you need to declare the Treeview
with self.tree
and do all other methods with self.tree
and so on.
I am not currently in front of a system, so I hope this code works and is not tested yet, let me know for any mistakes and changes.
you can use
for widgets in yourwidgetname.winfo_children(): widgets.destroy()
and reinitialize it by calling the function that initialize them
you can destroy all the widgets in a Frame by this way and it wont destroy completely your frame. it will destroy its child widgets.