首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在wxpython上使用‘`ListCtrl`’

如何在wxpython上使用‘`ListCtrl`’
EN

Stack Overflow用户
提问于 2019-04-22 04:34:47
回答 2查看 1K关注 0票数 0

如何将行及其对应的数据添加到ListCtrl中。我刚刚完成了如何使用TreeCtrl(相对于ListCtrl相对容易),它向我展示了匹配单个GUI对象和数据的明确用法。但ListCtrl没有。

  1. 如何添加或插入单行与其对应的数据。
  2. 我如何访问行和它的数据
  3. 如何操作它们(编辑数据/行,删除数据/行)

你能解释一下他们的总结吗?谢谢。我知道我的问题很简单,我可以从医生那里了解到这一点。我看过文档,但还是没有线索

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-22 05:11:54

我知道wxPython文档是弱智的,没有什么帮助,下面是一些快速提示,我在评论中添加了解释:

代码语言:javascript
复制
# 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)
票数 1
EN

Stack Overflow用户

发布于 2022-12-02 19:30:36

这就是对我有用的东西:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55789154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档