我正在运行一个简单的wxpythonlistctrl示例
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)
实现见下文:
相关问题 更多 >
编程相关推荐