python - 如何从 wxpython gui 单击事件获取列表数据?

标签 python wxpython

我有一个列表控制框,我用数据填充它。

self.listView1.Append([sFilename,sTitle,sArtist,sAlbum,sDestDir])

我创建了一个事件,当用户单击列表中的特定项目时触发

def OnListView1ListItemSelected(self, event):
    print "onListViewSelect"

这可行,但我所困惑的是如何从用户单击的列表中捕获单行数据?

最佳答案

使用 wxPython 2.8.10,这是将所选行中所有列中的文本拖放到列表中的一种方法。您将获取对象、选定的索引、列数,然后从每列中获取文本:

def onListView1ListItemSelected(self, event):
    obj     = event.GetEventObject()
    index   = event.GetIndex()
    columns = obj.GetColumnCount()
    data    = []

    for i in range(columns):
        item = obj.GetItem(index, i)
        data.append(item.GetText())

    print(data)

我提到这个版本是因为我认为最新的 wxPython 版本允许您在 wx.ListCtrl.GetItemText 中指定一列,这可以稍微简化一些事情。不过我还没试过。

关于python - 如何从 wxpython gui 单击事件获取列表数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4992963/

相关文章:

python - 如何使用多线程更新进度条以及下载文件

python - 显示另一个窗口 wxpython?

python - Django 集成开发环境 : how to start the devserver in an editor?

python - Pandas : transform a 2D dataframe to a 3D one

python - 类型错误 : unsupported operand type(s) for ** or pow(): 'MLinExpr' and 'int'

python - 在 wxPython 中,如何将 EVT_KEY_DOWN 事件绑定(bind)到整个窗口?

python - 避免在笔记本中单击退出 wxPython TreeCtrl

python - 给定一个句子,返回一个单词颠倒的句子

python - ModuleNotFoundError : no module named efficientnet. tfkeras

python - 绘制图表的最佳 Python 开源库是什么?