How do I get the text of the current selection of a wx.TreeCtrl widget?
The following code gives me an error:
self.tree.GetItemText(self.tree.GetSelection())
File "C:\Python27\lib\site-packages\wx-2.9.4-msw\wx\_controls.py", line
5262, in GetItemText
return _controls_.TreeCtrl_GetItemText(*args, **kwargs)
PyAssertionError: C++ assertion "item.IsOk()" failed at
..\..\src\msw\treectrl.cpp(949) in wxTreeCtrl::GetItemText(): invalid
tree item
Are you sure that there is a tree item selected when that code is run? You should be able to check if the item is valid with an if statement since the class has a __nonzero__ method. Something like this:
item = self.tree.GetSelection()
if item:
text = self.tree.GetItemText(item)
# Do something with text