gpt4 book ai didi

python - 使用 wxPython 在 UltimateListCtrl 中放置一个按钮

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:24 25 4
gpt4 key购买 nike

我是 Pythong 的新手,我一直在尝试在 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'

最佳答案

button 的父级应该是你的 ULCself.table

所以改变这一行:

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

为此:

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

响应评论更新:

出于某种原因,似乎无法删除 ULC 中的所有项目DeleteAllItems() 方法,如果任何项目包含小部件,请改用 DeleteItem()

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

关于python - 使用 wxPython 在 UltimateListCtrl 中放置一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3612934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com