2010-08-31 72 views
2

我是Pythong的新手,我一直試圖在UltimateListCtrl中獲得一個按鈕。我仍然無法弄清楚我做錯了什麼。這裏是我的代碼:使用wxPython在UltimateListCtrl中放置一個按鈕

try: 
    from agw import ultimatelistctrl as ULC 
except ImportError: # if it's not there locally, try the wxPython lib. 
    from wx.lib.agw import ultimatelistctrl as ULC 


self.table = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT| 
              ULC.ULC_HAS_VARIABLE_ROW_HEIGHT) 

self.table.InsertColumn(0, "Name") 
self.table.InsertColumn(1, "Size") 
self.table.InsertColumn(2, "Download") 


for i in range(0, len(masterlist)): 
    pos = self.table.InsertStringItem(i,str(masterlist[i]['name'])) 
    self.table.SetStringItem(pos, 1,str(masterlist[i]['size'])) 
    button = wx.Button(self, id=i, label="Download") 
    self.table.SetItemWindow(pos, col=2, wnd=button, expand=True) 

masterlist是一個下載項目的列表。

我得到這個回溯:

Traceback (most recent call last): 
File "E:\TestApp.py", line 67, in Display 
self.table.SetItemWindow(pos, col=5, wnd=button, expand=True) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 12961, in SetItemWindow 
return self._mainWin.SetItemWindow(item, wnd, expand) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 9021, in SetItemWindow 
item.SetWindow(wnd, expand) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 1863, in SetWindow 
mainWin = listCtrl._mainWin 
AttributeError: 'MainWindow' object has no attribute '_mainWin' 
+0

什麼是您傳遞給SetItemWindow的「pos」?發佈你的整個相關代碼,不只是這個小樣本 – 2010-08-31 21:14:23

+0

對不起,錯過了這個變量。這應該是相關的一切。 – FlowofSoul 2010-08-31 21:24:34

回答

3

button的父母應該是你ULCself.table

因此改變這一行:

button = wx.Button(self, id=wx.ID_ANY, label="Download") 

這樣:

button = wx.Button(self.table, id=wx.ID_ANY, label="Download") 

更新響應評論:

出於某種原因,它不似乎是可以刪除與 DeleteAllItems()方法,如果任何項目含有小部件在ULC的所有項目,以便改用DeleteItem()

def emptyList(self) 
    itemCount = self.list.GetItemCount() 
    for item in xrange(itemCount): 
     self.list.DeleteItem(0) 
+0

謝謝,這很好。 – FlowofSoul 2010-08-31 22:39:42

+0

很高興在這裏呢! – volting 2010-08-31 22:57:26

+0

當我嘗試「self.table.DeleteAllItems()」我得到這個錯誤消息:wx._core.PyDeadObjectError:Button對象的C++部分已被刪除,不再允許屬性訪問。你知道如何解決這個問題嗎?我沒有看到開放另一個問題的意義。 – FlowofSoul 2010-09-01 03:39:12