Button and Key Event

akameswaran at gmail.com akameswaran at gmail.com
Wed Mar 15 22:48:15 CET 2006

assuming you have a button instantiated and named myButton

in 2.6 (namespace is relevant I think prior to 2.4 you had a diff
namespace for wx)  for this example  i am guessing you are creating the
button as part of a panel or some other object you are extending (ie

self.myButton.Bind(wx.EVT_KEY_DOWN, self.OnLeftDownHandler )

Make sure you define a method OnLeftDownHandler on the parent object.

As a further thought is this really what you are trying to do?
Or do you want to know if a key is pressed when someone clicks on the
button?  Check the mouse events, I know you can check if control or
shift was pressed during a mouse click, not sure if you can do any
arbitrary key.  Binding the key event will not accomplish that if that
is what you want to know, well you might be able to torture around to
it if that's what you want.  The other problem is the key event should
only register if the button has keyboard focus - kind of an odd
situation.  So you may want to place the key listener on the parent

Or you may want to look into creating a custom event.  Hope this helps.
Also be warry of behavior of evt_char in windows.  Can't remember what,
but there is something funky there - I'm sure that was helpful ;)

More information about the Python-list mailing list