问题
In my small tkinter app I have tree with such scructure as in the picture below. I want to make click event only when user will double click to last item of the tree (Amount1 or Amount2 etc.) Unfortunatly click event works when I click any item of the tree. How fix this behavior?!
CODE:
self.treeView.insert('', 'end', "parent", text=text)
first_child = self.treeView.insert("parent", 'end', text=text)
second_child = self.treeView
second_child.insert(first_child, 'end', "", text=text)
second_child.bind("<Double-1>", self.OnDoubleClick)
def OnDoubleClick(self, event):
item = second_child.identify('item', event.x, event.y)
print("you clicked on", second_child.item(item, "text"))
Structure of the tree:
回答1:
https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/ttk-Treeview-events.html
Certain state changes within a Treeview widget generate virtual events that you can use to respond to these changes; see Section 54.8, “Virtual events”.
Whenever there is a change in the selection, either by items becoming selected or becoming unselected, the widget generates a “<<TreeviewSelect>>” event.
Whenever an item is opened, the widget generates a “<<TreeviewOpen>>” event.
Whenever an item is closed, the widget generates a “<<TreeviewClose>>” event.
来源:https://stackoverflow.com/questions/40533812/tkinter-treeview-click-event-for-selected-item