python - wxpython AttributeError:“ListCtrl”对象没有属性“EnableCheckBoxes”
问题描述
我正在运行一个简单的 wxpython ListCtrl 示例。
import wx
players = [('Tendulkar', '15000', '100'), ('Dravid', '14000', '1'),
('Kumble', '1000', '700'), ('KapilDev', '5000', '400'),
('Ganguly', '8000', '50')]
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title = title)
panel = wx.Panel(self)
box = wx.BoxSizer(wx.HORIZONTAL)
self.list = wx.ListCtrl(panel, -1, style = wx.LC_REPORT)
self.list.InsertColumn(0, 'name', width = 100)
self.list.InsertColumn(1, 'runs', wx.LIST_FORMAT_RIGHT, 100)
self.list.InsertColumn(2, 'wkts', wx.LIST_FORMAT_RIGHT, 100)
self.list.EnableCheckBoxes() # problem line
for i in players:
index = self.list.InsertStringItem(0, i[0])
self.list.SetStringItem(index, 1, i[1])
self.list.SetStringItem(index, 2, i[2])
box.Add(self.list,1,wx.EXPAND)
panel.SetSizer(box)
panel.Fit()
self.Centre()
self.Show(True)
ex = wx.App()
Mywin(None,'ListCtrl Demo')
ex.MainLoop()
但是,该行self.list.EnableCheckBoxes()
给了我错误AttributeError: 'ListCtrl' object has no attribute 'EnableCheckBoxes'
。如果我删除此行,我没有错误。
我在这里引用了 ListCtrl 的 wxpython 文档https://wxpython.org/Phoenix/docs/html/wx.ListCtrl.html?highlight=listctrl#wx.ListCtrl.EnableCheckBoxes它应该是受支持的功能。有人可以解释为什么我会收到属性错误吗?
解决方案
这是在 4.1.0 版本中引入的,因此可能是您运行的是旧版本的 wxPython。
它“启用”复选框,但不启用check
,尽管可以使用CheckItem(index,True)
.
见下文:
import wx
players = [('Tendulkar', '15000', '100'), ('Dravid', '14000', '1'),
('Kumble', '1000', '700'), ('KapilDev', '5000', '400'),
('Ganguly', '8000', '50')]
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title = title)
panel = wx.Panel(self)
box = wx.BoxSizer(wx.HORIZONTAL)
self.list = wx.ListCtrl(panel, -1, style = wx.LC_REPORT)
self.list.InsertColumn(0, 'name', width = 100)
self.list.InsertColumn(1, 'runs', wx.LIST_FORMAT_RIGHT, 100)
self.list.InsertColumn(2, 'wkts', wx.LIST_FORMAT_RIGHT, 100)
self.list.EnableCheckBoxes(True) # problem line
for i in players:
index = self.list.InsertItem(0, i[0])
self.list.SetItem(index, 1, i[1])
self.list.SetItem(index, 2, i[2])
self.list.CheckItem(index,True)
box.Add(self.list,1,wx.EXPAND)
panel.SetSizer(box)
panel.Fit()
self.Centre()
self.Show(True)
ex = wx.App()
Mywin(None,'ListCtrl Demo')
ex.MainLoop()
推荐阅读
- php - 如何在没有函数的 PHP 中设置和检索动态全局变量
- python - 我正在尝试从列表中删除死链接的 id(错误 403),但我的代码总是跳过一些 id,尽管它们已经死了,但它们重新出现在列表中
- google-app-engine - 云运行是否有套接字配额?
- sql - 如何重置 SQL Server 内置函数(DAY)
- python - 用 python 运行 gdb
- go - 如何在 Go 的 envconfig 库中使用“默认”结构标记?
- c++ - 静态成员重载和覆盖如何在 C++ 结构中工作?
- recursion - XSLT/Saxon 中的尾调用优化?
- electron - “不允许加载本地资源”与电子应用程序中的文件图像 URL
- php - Codeigniter 单个数据提取错误与结果