wxPython ListCtrl Help

2019-07-04 12:12发布

I'm using a ListCtrl and it is populated with items on the fly, when an item is "Activated"(Double Click/Enter) it calls a function.

    def onClick(self, event):

How do I find out which item was clicked in the List since they don't have pre-set IDs? Is the String passed to the function as part of self or event?

Thanks.

2条回答
女痞
2楼-- · 2019-07-04 12:45

Try event.GetText() or event.GetItem().<manipulate your item here>; here is wx.ListEvent documentation.

查看更多
叼着烟拽天下
3楼-- · 2019-07-04 12:45

Since you are probably binding the ListCtrl with the event, the ListCtrl item gets passed inside the event;

list = event.GetEventObject()
selected_string = list.GetStringSelection()

So now you have all ListCtrl methods available inside the event handler.

http://www.wxpython.org/docs/api/wx.Event-class.html

http://www.wxpython.org/docs/api/wx.TextCtrl-class.html

查看更多
登录 后发表回答