2

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:

enter image description here

Community
  • 1
  • 1
Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193
  • 1
    simply add a check in `OnDoubleClick` and do nothing if the user didn't click on the last item. – Bryan Oakley Nov 10 '16 at 20:10
  • In my case I want to make click event only to second_child elements (Example: Amount). As I understand I need to check what element was clicked inside OnDoubleClick, yes? Can you explain it with little code. I am little bit confused. – Nurzhan Nogerbek Nov 11 '16 at 03:07
  • @BryanOakley Can you check my code again pls. I update my code still dont know whats wrong with OnDoubleClick. – Nurzhan Nogerbek Nov 11 '16 at 10:56

1 Answers1

6

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.

Community
  • 1
  • 1