首页 > 代码库 > wxPython treeCtrl树节点递归遍历(复制)

wxPython treeCtrl树节点递归遍历(复制)

下面是递归遍历、获取树节点的方法。

 1     def getTreeAllText(self): 2         ‘‘‘获取树控件的全部文本‘‘‘ 3         result = [] 4         treeRoot = self.treeCtrl.GetRootItem() 5         rootText = self.treeCtrl.GetItemText(treeRoot) 6         result.append(u+rootText) 7         def recursivelyGetTreeItem(tree,leval): 8             ‘‘‘ 递归遍历TreeCtrl的所有孩子 ‘‘‘ 9             (item,cookie) = self.treeCtrl.GetFirstChild(tree)10             while item.IsOk():11                 ItemStr = u├%s%s % (u*leval,self.treeCtrl.GetItemText(item))12                 result.append(ItemStr)13                 if self.treeCtrl.GetChildrenCount(item)>0:14                     leval+=115                     recursivelyGetTreeItem(item,leval)16                     leval-=117                 (item,cookie) = self.treeCtrl.GetNextChild(item,cookie)18                 19         leval = 0   #递归的子树层次20         recursivelyGetTreeItem(treeRoot,leval)21         return \n.join(result)

 设置文本内容到剪贴板

1 def CopyToClipboard(text):2     do = wx.TextDataObject()3     do.SetText(text.encode(gb2312))4     if wx.TheClipboard.Open():5         wx.TheClipboard.SetData(do)6         wx.TheClipboard.Close()7     else:8         wx.MessageBox("Unable to open the clipboard", "Error")

 

wxPython treeCtrl树节点递归遍历(复制)