📌  相关文章
📜  wxPython – wx.TreeCtrl 中的 AssignImageList() 方法

📅  最后修改于: 2022-05-13 01:54:24.178000             🧑  作者: Mango

wxPython – wx.TreeCtrl 中的 AssignImageList() 方法

在本文中,我们将学习与 wxPython 的 wx.TreeCtrl 类关联的 AssignImageList() 方法。 AssignImageList()函数用于设置普通图像列表。使用此方法分配的图像列表将由 wx.TreeCtrl 酌情自动删除(即它拥有列表的所有权)。
AssignImageList() 接受 wx.ImageList 参数。

代码示例:

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()


输出窗口: