Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython – AppendItem() method in wx.TreeCtrl

  • Last Updated : 08 Jul, 2020

In this article we will learn about AppendItem() method in wx.TreeCtrl class of wxPython. AppendItem() method is used to append an item to the end of the branch identified by parent, return a new item id.

Append() method takes parent(wx.TreeItemId) as parameter.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Syntax: wx.TreeCtrl.AppendItem()



Parameters

ParameterInput TypeDescription
parentwx.TreeItemIdparent root for Item.
textstringtext on node
imageintimage parameter is an index within the normal image list specifying the image to unselected items, respectively.
selImageintselImage parameter is an index within the normal image list specifying the image to selected items, respectively.
dataTreeItemDatadata for root item.

Return Type: wx.TreeItemId

Code Example:




import wx
  
class MainFrame(wx.Frame):
  
    def __init__(self):
        wx.Frame.__init__(self, parent = None, title ='TreeCtrl Demo')
        # tree control
        self.tree = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
  
        # add a root node to tree
        self.root = self.tree.AddRoot('Root ')
  
        # add item to self.root
        self.tree.AppendItem(self.root, "Item")
  
        # expand tree
        self.tree.Expand(self.root)
  
        # show frame
        self.Show()
  
  
if __name__ == '__main__':
    app = wx.App(redirect = False)
    frame = MainFrame()
    app.MainLoop()

Output Window:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!