2016-06-23 22 views
0

在GUI中,我使用填充了許多wx.lib.agw.ultimatelistctrl(ULC)的wx.Treebook切片wxPython WindowList

我需要遍歷樹形圖書頁(又名ULCs)。
我用lPages = treebook.GetChildren()來得到它們。

但是,樹形圖的第一個孩子是wx.TreeCtrl的一個實例。

我知道我可以用類似避免:

for page in lPages: 
    if not isinstance(page, wx.TreeCtrl): 
     # do something with the ULCs 

但我想保持我的代碼簡單,容易閱讀。因此,不要將測試用於單次使用並保留額外縮進。
我想要做一些像lPages = treebook.GetChildren()[1:]del lPages[0]只能得到ULCs。

它給我以下錯誤:

使用treebook.GetChildren()[1:]

TypeError: WindowList.__getitem__(): argument 1 has unexpected type 'slice' 
Segmentation fault (core dumped) 

使用del lPages[0]

TypeError: 'WindowList' object doesn't support item deletion 
Segmentation fault (core dumped) 

有沒有什麼辦法來分割一個WindowList中?

回答

1

GetChildren返回的對象不是實際的Python列表,而是模仿列表的某些行爲的C++對象。你可以將其轉換爲使用list(),這樣一個真正的名單:

lPages = list(treebook.GetChildren()) 

然後,你可以做你的切片或任何你需要一個列表對象。請注意,更改lPages中的項目順序或刪除項目不會影響窗口的實際子項。一旦你將它轉換爲list()那麼這只是原始集合的副本。