我正在尝试使用 TreeCtrl 来表示文件夹结构。对于每个文件夹,我需要知道它的绝对路径和名称。我目前正在做这样的事情:
self.root = self.tree.AddRoot(project.name)
self.tree.SetPyData(self.root, None)
self.root.path = root
---- other code -----
childItem = self.tree.AppendItem(self.root, child.name)
childItem.path = self.root.path + "/" + child.name
但现在在一个事件中,我需要获取路径字符串。到目前为止,我失败的方法是:
self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree)
----- other code -------
def OnItemExpanded(self, evt):
selected = evt.GetItem()
print selected.path
现在失败了,因为: AttributeError: 'TreeItemId' object has no attribute 'path' 。据我了解,该事件只给了我一个来自树的项目的 ID,而不是由 "childItem = self.tree.AppendItem(self.root, child.name)" 产生的实际项目?如果是这种情况,我怎样才能得到那个项目?
问候,波格丹