python - wxPython:ListCtrl查找具有给定字符串的项目

标签 python find wxpython listctrl

我已经创建了一个wx.ListCtrl并且我已经填写了内容。如何检索具有给定字符串的项目?

我使用了FindItem,但它总是返回-1(未找到)。难道是我使用不当?

print self.List.FindItem(-1, "kid_inst")

>>> -1

我有:wxPython 2.8.10.1、Windows 7、Python 2.4

最佳答案

它似乎只适用于第一列:

import wx

class MainWindow(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.panel = wx.Panel(self)
        self.list = wx.ListCtrl(self.panel, style=wx.LC_REPORT)
        self.list.InsertColumn(0, "No.")
        self.list.InsertColumn(1, "Description")
        self.list.Arrange()

        for i in range(1, 6):
            self.list.Append(["It's %d" % (i), "", ""])
            # DOES NOT WORK! self.list.Append(["", "It's %d" % (i), ""])

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.list, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
        self.panel.SetSizerAndFit(self.sizer)
        self.Show()

        print(self.list.FindItem(-1, "It's 4"))


app = wx.App(False)
win = MainWindow(None)
app.MainLoop()

还有更复杂的方法可以通过创建wx.ListItem()来将项目添加到列表中,并且SetItemData可用于向项目添加更多数据。然后您可能可以执行FindItemData。但我从来没有这样做过,所以我无法提供帮助。

关于python - wxPython:ListCtrl查找具有给定字符串的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20417392/

相关文章:

在 HIVE 中查找函数

python - 如何用wxpython直接在屏幕上绘图?

python - Numpy 导入抛出 AttributeError : 'module' object has no attribute 'core'

python - 为什么类在未启动时会得到 "called"? - Python

python 检查字典值是否由字符串列表组成

python - 没有检查约束的 Alembic 自动生成迁移

unix - 仅列出目录中匹配单词 BOZO 并以 '123' 或 '456' 结尾的某些文件

batch-file - 批处理文件find解析出关键字

python - wxPython RichTextCtrl 带删除线

python - 最Pythonic的方式来处理对话框?