在本文中,我們將學習與wxPython的wx.TreeCtrl類關聯的AddRoot()方法。 AddRoot()是用於將根節點添加到樹中並返回新項目的基本方法。
image和selImage參數是普通圖像列表中的索引,分別指定要用於未選擇項和選定項的圖像。如果image> -1且selImage為-1,則同一圖像同時用於選定和未選定項目。
用法: wx.TreeCtrl.AddRoot(self, text, image=-1, selImage=-1, data=None)
參數
參數 | 輸入類型 | 描述 |
---|---|---|
text | string | 節點上的文本 |
image | int | image參數是普通圖像列表中的索引,分別將圖像指定為未選中的項目。 |
selImage | int | selImage參數是普通圖像列表中的索引,分別為所選項目指定圖像。 |
data | TreeItemData | 根項目的數據。 |
代碼示例:
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 ')
# 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.RadioBOx IsItemShown()用法及代碼示例
- wxPython wx.RadioBox IsItemEnabled()用法及代碼示例
- wxPython wx.TreeCtrl CollapseAndReset()用法及代碼示例
- wxPython wx.ToolBar AddControl()用法及代碼示例
- wxPython wx.TreeCtrl CollapseAllChildren()用法及代碼示例
- wxPython wx.TreeCtrl CollapseAll()用法及代碼示例
- wxPython wx.RadioBox ShowItem()用法及代碼示例
- wxPython wx.RadioBox SetString()用法及代碼示例
- wxPython wx.RadioBox SetSelection()用法及代碼示例
- wxPython wx.RadioBox SetItemLabel()用法及代碼示例
- wxPython wx.RadioBox GetItemToolTip()用法及代碼示例
- wxPython wx.RadioBox GetString()用法及代碼示例
- wxPython wx.RadioBox SetItemToolTip()用法及代碼示例
- wxPython wx.TreeCtrl ClearFocusedItem()用法及代碼示例
- wxPython wx.StaticBox Enable()用法及代碼示例
- wxPython wx.RadioBOx SetItemHelpText()用法及代碼示例
- wxPython wx.TreeCtrl AppendItem()用法及代碼示例
- wxPython wx.TreeCtrl AssignImageList()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – AddRoot() method in wx.TreeCtrl。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。