- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 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
的父级应该是你的 ULC
即 self.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/
我想创建一个基于最终列表 ctrl 的表格,用户可以在其中通过单击列标题对列进行排序。这是我尝试的代码: import wx import wx.lib.mixins.listctrl as list
我似乎无法调用 UltimateListCtrl.ScreenToClient(pos)。我不断收到类型错误。我输入一个 (x,y) 元组,然后得到 TypeError: ScreenToClient
我是 Pythong 的新手,我一直在尝试在 UltimateListCtrl 中获取一个按钮。我仍然无法弄清楚我做错了什么。这是我的代码: try: from agw import ulti
我正在使用 UltimateListCtrl 和 LC_LIST 样式。我的列表中的所有项目都带有复选框。填充列表后,我尝试根据从数据库收到的数据动态检查(勾选)一些项目。但在填充列表后,我无法检查(
我是一名优秀的程序员,十分优秀!