當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.TreeCtrl ExpandAll()用法及代碼示例

在本文中,我們將學習與wxPython的wx.TreeCtrl類關聯的ExpandAll()方法。 ExpandAll()方法類似於Expand(),但是唯一的區別是該方法用於擴展樹控件中存在的所有項目。使用此方法可以看到所有子節點以及那裏的父節點。

此方法不需要任何參數。

用法:wx.TreeCtrl.ExpandAll(self)

參數:

此方法不需要任何參數。



代碼示例:

Python

import wx  
  
  
class MyTree(wx.TreeCtrl):  
  
    def __init__(self, parent, id, pos, size, style):  
        wx.TreeCtrl.__init__(self, parent, id, pos, size, style)  
  
  
class TreePanel(wx.Panel):  
  
    def __init__(self, parent):  
        wx.Panel.__init__(self, parent)  
          
        # create tree control in window  
        self.tree = MyTree(self, wx.ID_ANY, wx.DefaultPosition,  
                           wx.DefaultSize, wx.TR_HAS_BUTTONS)  
          
        # CREATE TREE ROOT  
        self.root = self.tree.AddRoot('root')  
        self.tree.SetPyData(self.root, ('key', 'value'))  
  
        # add item to root  
        item = self.tree.AppendItem(self.root, "Item")  
        item2 = self.tree.AppendItem(self.root, "Item")  
        item3 = self.tree.AppendItem(item, "SubItem") 
  
        # expand all nodes of the tree 
        self.tree.ExpandAll()  
          
        sizer = wx.BoxSizer(wx.VERTICAL)  
        sizer.Add(self.tree, 0, wx.EXPAND)  
        self.SetSizer(sizer)  
  
  
class MainFrame(wx.Frame):  
  
    def __init__(self):  
        wx.Frame.__init__(self, parent = None, title ='TreeCtrl Demo')  
        panel = TreePanel(self)  
        self.Show()  
  
  
if __name__ == '__main__':  
    app = wx.App(redirect = False)  
    frame = MainFrame()  
    app.MainLoop()

輸出:





相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – ExpandAll() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。