My Python program has two classes that are basically modified versions of Tkinter's Treeview Widget. The reason for the two different classes is that they have different methods for when items within them are double-clicked, selected etc.
The program creates an instance of each class, named tree_dialog_tv1 and tree_dialog_tv2 respectively.
I have a method in the class for the tree_dialog_tv1 bound to double-click that highlights the current row, or un-highlights if, if already highlighted. The instance of the second class, tree_dialog_tv2, is meant to list a copy of only the rows in tree_dialog_tv1 that are currently selected, adding new selections added in tree_dialog_tv1 and removing any unselected in tree_dialog_tv1.
What I don't know is where to put the code for adding/removing items in tree_dialog_tv2 based on the items double-clicked in tree_dialog_tv1. Should this code be added to the existing double-click-bound method in the class for tree_dialog_tv1, and if so, how should I reference the tree_dialog_tv2 instance (which belongs to a completely difference class) so that its contents can be updated?
class MyTreeview1(ttk.Treeview):
def __init__(self, master, **kw):
super().__init__(master, **kw)
self.bind("<<TreeviewSelect>>", self.on_tree_item_select)
def on_tree_item_select(self, event):
#code for highlighting/unhighlighting rows here
class MyTreeview2(ttk.Treeview):
def __init__(self, master, **kw):
super().__init__(master, **kw)
self.bind("<Double-1>", self.on_double_click)
def on_double_click(self, event):
#various lines of code (omitted for simplicity)
if __name__ == "__main__":
tree_dialog_tv1 = MyTreeview1(root)
tree_dialog_tv2 = MyTreeview2(root)
tree_dialog_tv1.grid(row=0,column0)
tree_dialog_tv2.grid(row=0,column1)
root.mainloop()
Ultimately actions in instance of one Treeview class need to affect contents of instance of completely different Treeview class, but not sure how to call.