Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

wxPython – AssignImageList() method in wx.TreeCtrl

  • Last Updated : 17 Jun, 2021

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)

 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

ParameterInput TypeDescription
imageListwx.ImageListImage 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
Recommended Articles
Page :

Start Your Coding Journey Now!