Open In App

wxPython – AssignImageList() method in wx.TreeCtrl

Improve
Improve
Like Article
Like
Save
Share
Report

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: 

 



Last Updated : 17 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads