求教怎么在listbox列表中,选中某item后回车执行事件
求教如何在listbox列表中,选中某item后回车执行事件
请教怎么能够在选中某列表后按回车执行事件呢,谢谢!
#coding=utf-8
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example', size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five','six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen']
listBox = wx.ListBox(panel, -1, (20, 20), (80, 120), sampleList, wx.LB_SINGLE)
if __name__ == '__main__':
app = wx.PySimpleApp()
ListBoxFrame().Show()
app.MainLoop()
------解决思路----------------------
请教怎么能够在选中某列表后按回车执行事件呢,谢谢!
#coding=utf-8
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example', size=(250, 200))
panel = wx.Panel(self, -1)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five','six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen']
listBox = wx.ListBox(panel, -1, (20, 20), (80, 120), sampleList, wx.LB_SINGLE)
if __name__ == '__main__':
app = wx.PySimpleApp()
ListBoxFrame().Show()
app.MainLoop()
------解决思路----------------------
#!/usr/bin/python
#coding=utf-8
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example', size=(250, 200))
self.panel = wx.Panel(self, wx.ID_ANY)
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five','six', 'seven',
'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen']
listBox = wx.ListBox(self.panel, -1, (20, 20), (80, 120), sampleList, wx.LB_SINGLE)
self.panel.Bind(wx.EVT_KEY_UP, self.OnKeyDown)
self.panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.panel.Bind(wx.EVT_CHAR, self.OnKeyDown)
def OnKeyDown(self, event=None):
print "key event %s" %(event.GetKeyCode())
if __name__ == '__main__':
app = wx.PySimpleApp()
ListBoxFrame().Show()
app.MainLoop()