I'm trying to capture keyboard events that happen inside a wx.Frame, and I would expect the following code to capture those events. However, the handler OnKeyDown is never called when I run the code:
import logging as log
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
self.Bind(wx.EVT_KEY_UP, self.OnKeyDown)
self.Bind(wx.EVT_CHAR, self.OnKeyDown)
self.SetFocus()
self.Show(True)
def OnKeyDown(self, event=None):
log.debug("OnKeyDown event %s" % (event))
if __name__ == "__main__":
app = wx.App(False)
gui = MainWindow(None, "test")
app.MainLoop()
If anyone knows how to do this, I would appreciate some help.