How should you get the item selected in wxTreeCtrl? I bind the method to the activated item like this:
self.tree.Bind (wx.EVT_TREE_ITEM_ACTIVATED, self.OnAdd, id=10)
And in the method OnAdd I try to get the item:
def OnAdd(self, event):
item = event.GetItem()
But it gives error that event has no GetItem() method. Any idea?
UPDATE:
I had assigned a button event to process selected item.
So that’s why the event had not item attached to it..
You are binding the callback incorrectly. You currently do:
But the 3rd parameter is the
source;idis the 4th parameter. So, change it to this:This way, the
eventargument you will get in yourOnAddfunction will be thetreeinstance, which will have theGetItemmethod available.Full example: