Thursday, October 23, 2025
HomeLanguageswxPython – AppendItem() method in wx.TreeCtrl

wxPython – AppendItem() method in wx.TreeCtrl

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.

Syntax: wx.TreeCtrl.AppendItem()

Parameters

Parameter Input Type Description
parent wx.TreeItemId parent root for Item.
text string text on node
image int image parameter is an index within the normal image list specifying the image to unselected items, respectively.
selImage int selImage parameter is an index within the normal image list specifying the image to selected items, respectively.
data TreeItemData data 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:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS