Subject:
Re: [wxPython-users] Initial keyboard focus
From:
Robin Dunn <robin@alldunn.com>
Date:
Thu, 04 May 2006 17:04:19 -0700
To:
wxPython-users@lists.wxwidgets.orgJames Bigler wrote:
I'm using python-wxGTK 2.5.3.1-5 on Suse 9.3.
I have a top level frame that I put a wxGLCanvas in. When I first start the program the canvas receives EVT_MOTION events without having to click in it first. However, EVT_KEY_DOWN or EVT_CHAR events require me to click in the canvas first. Once I click in the canvas, keyboard events are captured as long as the window has focus (the mouse doesn't even need to be in the window).
Any ideas of how to get keyboard events to the wxGLCanvas with window focus when the program starts (i.e. before clicking in the canvas)?
def main():
app = wxPySimpleApp()
frame = wxFrame(None,-1,'ball_wx',wxDefaultPosition,wxSize(400,400))
canvas = myGLCanvas(frame)Try adding this:
wx.CallAfter(canvas.SetFocus)
frame.Show()
app.MainLoop()if __name__ == '__main__': main()
This worked like a charm.
Thanks!
James