Это работает для меня, ключ для Bind EVT_KEY_UP, а не EVT_KEY_DOWN:
import wx
class myListBoxDemo(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent=parent, title="testing ListBox right-click")
self.panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.myListBox = wx.ListBox(self.panel,style=wx.LB_HSCROLL|wx.LB_SINGLE)
self.myListBox.Bind(wx.EVT_KEY_UP, self.OnKeyDownSelectedList)
self.myListBox.Append('item 1')
self.myListBox.Append('item 2')
self.myListBox.Append('item 3')
self.myListBox.Append('item 4')
sizer.AddF(self.myListBox, wx.SizerFlags(1).Expand())
self.panel.SetSizer(sizer)
def OnKeyDownSelectedList(self, event):
print "KeyCode: %d" % event.GetKeyCode()
print "ListBox Item Index: %d" % event.GetEventObject().GetSelection()
import wx.lib.mixins.inspection as wit
class AppWInspection(wx.App, wit.InspectionMixin):
def OnInit(self):
self.Init() # enable Inspection tool
return True
if __name__ == "__main__":
app = AppWInspection()
f = myListBoxDemo(None)
f.Show()
app.MainLoop()