如何在wxpython上使用`ListCtrl`

时间:2019-04-22 04:34:47

标签: python wxpython listctrl

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

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

您能解释一下它们的摘要吗?谢谢。 我知道我的问题很简单,我可以从doc中获得一些信息。 我读过文档,但仍然没有头绪

1 个答案:

答案 0 :(得分:0)

我知道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)
相关问题