I have a program that displays some data from MySQL using Treeview. I would like to update the contents of it using a "refresh button" instead of terminating and re-running the program again. I have tried self.destroy() function, but it closes the tab and doesn't reopen the tab. Are there other ways to just refresh the Treeview?
class tab_four(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
...
#tree.heading("#0", text = " ")
tree.heading("1", text = "Equipment Type")
tree.heading("2", text = "Total")
tree.heading("3", text = "Unavailable")
tree.heading("4", text = "Available")
#tree.column('#0', stretch = NO, minwidth = 0, width = 0)
tree.column('#1', stretch = YES, minwidth = 0, width = 100, anchor = CENTER)
tree.column('#2', stretch = YES, minwidth = 0, width = 100, anchor = CENTER)
tree.column('#3', stretch = YES, minwidth = 0, width = 100, anchor = CENTER)
tree.column('#4', stretch = YES, minwidth = 0, width = 100, anchor = CENTER)
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()
for row in display:
tree.insert("", "end", values=row)
def refresh_clicked(self):
self.destroy()
self.__init__()
button_refresh = tk.Button(topframe, text = "Refresh", state = NORMAL, command = self.refresh_clicked)
button_refresh.grid(row = 1, column = 2, sticky = W, padx = 5, pady = 2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…