在本文中,我們將學習與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()
輸出窗口:
相關用法
- wxPython wx.TreeCtrl CollapseAndReset()用法及代碼示例
- wxPython wx.StaticBox Enable()用法及代碼示例
- wxPython wx.RadioBOx IsItemShown()用法及代碼示例
- wxPython wx.RadioBox SetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox SetSelection()用法及代碼示例
- wxPython wx.TreeCtrl AppendItem()用法及代碼示例
- wxPython wx.RadioBOx SetItemHelpText()用法及代碼示例
- wxPython wx.ToolBar AddControl()用法及代碼示例
- wxPython wx.TreeCtrl CollapseAllChildren()用法及代碼示例
- wxPython wx.RadioBox IsItemEnabled()用法及代碼示例
- wxPython wx.RadioBox SetItemLabel()用法及代碼示例
- wxPython wx.RadioBox GetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox GetString()用法及代碼示例
- wxPython wx.TreeCtrl ClearFocusedItem()用法及代碼示例
- wxPython wx.StaticLine GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.StaticLine GetDefaultSize()用法及代碼示例
- wxPython wx.TreeCtrl Delete()用法及代碼示例
- wxPython wx.ToolBar AddSeparator()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – AssignImageList() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。