當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


wxPython wx.TreeCtrl AssignImageList()用法及代碼示例

在本文中,我們將學習與wxPython的wx.TreeCtrl類關聯的AssignImageList()方法。 AssignImageList()函數用於設置普通圖像列表。分配給該方法的圖像列表將由wx.TreeCtrl自動刪除(即,它擁有列表的所有權)。
AssignImageList()帶有wx.ImageList參數。

用法: wx.TreeCtrl.AssignImageList(self, imageList)

參數

參數 輸入類型 描述
imageList wx.ImageList 圖像列表分配給Tree控件。

代碼示例:

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

輸出窗口:




相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – AssignImageList() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。