Skip to content
Related Articles

Related Articles

wxPython – AssignImageList() method in wx.TreeCtrl

Improve Article
Save Article
  • Last Updated : 17 Jun, 2021
Improve Article
Save Article

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)

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


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)
        # 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
        # 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
        # show frame
if __name__ == '__main__':
    app = wx.App(redirect = False)
    frame = MainFrame()

Output Window: 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!