【问题标题】:How to use `ListCtrl` on wxpython如何在 wxpython 上使用`ListCtrl`
【发布时间】:2019-09-11 08:04:53
【问题描述】:

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

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

你能解释一下它们的概要吗?谢谢你。 我知道我的问题很简单,我可以从 doc 那里得到一些信息。 我阅读了文档,但仍然没有任何线索

【问题讨论】:

  • 你的问题太宽泛了。除了在 Stackoverflow 上,你应该显示你的代码,完整的错误信息,然后我们可以尝试解决这个问题。
  • 这是一个完整教程的请求,而不是一个问题

标签: python wxpython listctrl


【解决方案1】:

我知道 wxPython 文档很迟钝,没有提供太多帮助,下面是一些快速提示, 我在 cmets 中添加了解释:

# 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)

【讨论】:

  • 似乎,数据和它的单元格的标签有点无关对吧?看起来数据附件和标签附件的工作方式不同。
  • 对,标签什么都不是,整个东西更像Microsoft Excel,你可以通过它的位置(行,列)访问cel,或者只是过去一整行,添加时要小心行,项目数必须与列数相匹配,否则你会得到一个奇怪的行为或错误
  • 所以如果我仔细放置数据和标签,我可以通过标签索引访问特定行数据。(行和数据索引的顺序应该相同)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 2014-04-05
相关资源
最近更新 更多