Para eso existe el evento
EVT_TREE_ITEM_ACTIVATED
Un ejemplo de su uso
Código Python:
Ver original#coding: utf-8
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Tree", size=(400,500))
# Creamos el tree
self.tree = wx.TreeCtrl(self)
# Añadimos una raiz
self.root = self.tree.AddRoot("Raiz")
# Añadimos ramas (o nodos) a nuestra raiz
self.branches = [
["Rama1",
["SubRama1EnRama1", "SubRama2EnRama1"]],
["Rama2",
["SubRama1EnRama2", "SubRama2EnRama2"]]
]
self.AddTreeNodes(self.root, self.branches) #Metodo de clase
# Expandimos el primer nivel
self.tree.Expand(self.root)
self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnDoubleClick)
#self.tree.Bind(wx.EVT_TREE_KEY_DOWN, self.OnEnter)
def OnDoubleClick(self, event):
print self.tree.GetItemText(event.GetItem())
def AddTreeNodes(self, root, items):
for item in items:
if type(item) == str:
self.tree.AppendItem(root, item)
else:
newItem = self.tree.AppendItem(root, item[0])
self.AddTreeNodes(newItem, item[1])
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()