tkinter treeview click event for selected item [duplicate]

こ雲淡風輕ζ 提交于 2020-06-28 04:17:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!