Skip to content
Related Articles

Related Articles

wxPython – Expand() method in wx.TreeCtrl

View Discussion
Improve Article
Save Article
  • Last Updated : 25 Nov, 2020

In this article, we are going to learn about Expand() method associated with wx.TreeCtrl class of wxPython. Expand() method is used in order to expand and show children nodes of a particular item in Tree Control.

This function takes the tree node item as a parameter to whom we want to expand.

Syntax: wx.TreeCtrl.Expand(self, item)


Parameters Type Description
item wx.TreeItemId Item that we want to associate editlabel with.

Code Example:


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) 
        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"
        # expand root 
        sizer = wx.BoxSizer(wx.VERTICAL) 
        sizer.Add(self.tree, 0, wx.EXPAND) 
class MainFrame(wx.Frame): 
    def __init__(self): 
        wx.Frame.__init__(self, parent = None, title ='TreeCtrl Demo'
        panel = TreePanel(self
if __name__ == '__main__'
    app = wx.App(redirect = False
    frame = MainFrame() 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!