Wednesday, May 6, 2026
HomeLanguageswxPython – AssignImageList() method in wx.TreeCtrl

wxPython – AssignImageList() method in wx.TreeCtrl

In this article, we are going to learn about AssignImageList() method associated with wx.TreeCtrl class of wxPython. AssignImageList() function is used in order to set the normal image list. The image list assigned with this method will be automatically deleted by wx.TreeCtrl as appropriate (i.e. it takes ownership of the list). 
AssignImageList() takes wx.ImageList argument.

Syntax: wx.TreeCtrl.AssignImageList(self, imageList)
Parameters 
 

Parameter Input Type Description
imageList wx.ImageList Image list to assign to Tree control.

 

Code Example:  

Python3




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)
 
        # create imagelist
        il = wx.ImageList(16, 16)
 
        # add images to image list
        one = il.Add(wx.Image('plus.png', wx.BITMAP_TYPE_PNG).Scale(16, 16).ConvertToBitmap())
        two = il.Add(wx.Image('close.png').Scale(16, 16).ConvertToBitmap())
 
        # assign image list to tree
        self.tree.AssignImageList(il)
 
        # add a root node to tree
        self.root = self.tree.AddRoot('Root ', 0)
 
        # add item to self.root
        self.tree.AppendItem(self.root, "Item", 1)
 
        # 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
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6890 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS