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


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

在本文中,我們將學習wxPython的wx.TreeCtrl類中的AppendItem()方法。 AppendItem()方法用於將一個項目附加到父項標識的分支的末尾,並返回一個新的項目ID。

Append()方法將parent(wx.TreeItemId)作為參數。

用法: wx.TreeCtrl.AppendItem()

參數

參數 輸入類型 描述
parent wx.TreeItemId Item的父根。
text string 節點上的文本
image int image參數是普通圖像列表中的索引,分別將圖像指定為未選中的項目。
selImage int selImage參數是普通圖像列表中的索引,分別為所選項目指定圖像。
data TreeItemData 根項目的數據。

返回類型:wx.TreeItemId

代碼示例:

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) 
  
        # add a root node to tree 
        self.root = self.tree.AddRoot('Root ') 
  
        # add item to self.root 
        self.tree.AppendItem(self.root, "Item") 
  
        # 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 – AppendItem() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。