wxPython ListCtrl Help

2019-07-04 12:18发布

问题:

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.

回答1:

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



回答2:

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