如何将行及其对应的数据添加到ListCtrl中。我刚刚完成了如何使用TreeCtrl(相对于ListCtrl相对容易),它向我展示了匹配单个GUI对象和数据的明确用法。但ListCtrl没有。
你能解释一下他们的总结吗?谢谢。我知道我的问题很简单,我可以从医生那里了解到这一点。我看过文档,但还是没有线索
发布于 2019-04-22 05:11:54
我知道wxPython文档是弱智的,没有什么帮助,下面是一些快速提示,我在评论中添加了解释:
# create new list control
listctrl = wx.dataview.DataViewListCtrl( my_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.dataview.DV_SINGLE )
# setup listctrl columns
listctrl.AppendTextColumn('first name', width=220) # normal text column
listctrl.AppendBitmapColumn('my images', 0, width=35) # you can add images in this col
listctrl.AppendProgressColumn('Progress', align=wx.ALIGN_CENTER) # a progress bar
listctrl.SetRowHeight(30) # define all rows height
# add data, note myList is a list or tuple contains the exact type of data for each columns and same length as col numbers
listctrl.AppendItem(myList)
# to modify an entry "a single cell located at row x col"
listctrl.SetValue(myNewValue, row, column)发布于 2022-12-02 19:30:36
这就是对我有用的东西:
import wx
il_icons = wx.ImageList(16, 16, mask=True, initialCount=2)
il_icons.Add(wx.Bitmap('icon01.png'))
il_icons.Add(wx.Bitmap('icon02.png'))
lc_list = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_EDIT_LABELS | wx.LC_VRULES, name='lc_list')
lc_list.AssignImageList(il_icons, which=wx.IMAGE_LIST_SMALL)
lc_list.AppendColumn('col01', format=wx.LIST_FORMAT_LEFT, width=64)
lc_list.AppendColumn('col02', format=wx.LIST_FORMAT_RIGHT, width=64)
lc_list.Append(('item01',100))
lc_list.Append(('item02',200))
lc_list.SetItemColumnImage(0,0,0)
lc_list.SetItemColumnImage(1,0,1)
lc_list.Bind(wx.EVT_LIST_ITEM_SELECTED, OnItemSelected)
lc_list.Show(True)https://stackoverflow.com/questions/55789154
复制相似问题