By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,496 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,496 IT Pros & Developers. It's quick & easy.

Some issue with right click in TreeCtrl

P: n/a
Hello All,

Please find the code for a simple wx.TreeCtrl code. Whenever I right click
on any item in the Tree, I see the function, 'OnSelChanged' gets called

What I've just done is that I've associated the function 'OnRightClick' with
wx.EVT_TREE_ITEM_RIGHT_CLICK. And in this function, I say
self.tree.SelectItem(evt.GetItem(),True) to select the item and then so some
action for right click.

Can any one help.

Thanks & Regards,

*Please find the code in the attachment and also below:-*

import wx
tests = ["All Tests",
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Simple Tree", size=(400,500))
# Create the tree
self.tree = wx.TreeCtrl(self)
# Add a root node
root = self.tree.AddRoot(tests[0])
# Add nodes from our data set
self.AddTreeNodes(root, tests, 0)
# Bind some interesting events
self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree)
self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnRightClick,
# Expand the first level

def AddTreeNodes(self, father, aTestList,count):
if type(aTestList) == type([]):
l = len(aTestList)
i = 0
while i < l:
if i == 0:
if count ==1:
father = self.tree.AppendItem(father, aTestList[i])
self.AddTreeNodes(father, aTestList[i],
i = i + 1
if type(aTestList) == type(""):
self.tree.AppendItem(father, aTestList)

def OnRightClick(self, evt):
print 'In OnRightClick Function...',self.GetItemText(evt.GetItem())

def GetItemText(self, item):
if item:
return self.tree.GetItemText(item)
return ""

def OnSelChanged(self, evt):
print "OnSelChanged: ", self.GetItemText(evt.GetItem())

app = wx.PySimpleApp(redirect=True)
frame = TestFrame()

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.