wxPython: Transferring keyboard events from one frame to another

Josiah Carlson jcarlson at nospam.uci.edu
Tue Feb 3 23:05:19 EST 2004


> Hi Josiah,
> My virtual keypad is used for text entry with a mouse, but I also want
> to transfer regular keyboard key presses from the keypad to the
> 'client' window.

If your virtual keypad is a subclass of wxDialog, you're going to have a 
problem.  wxDialogs eat keypresses if you are not careful, especially 'tab'.

You should instead try to use a plain wxFrame or wxMiniFrame (check the 
wxPython demo for code).  Then just ignore keyboard events in the keypad 
window (using event.Skip()), they should be passed up the parent 
heirarchy and get to your main application without much effort.  If this 
doesn't work for you, here's what I like to do:

#parent frame
     def OnKeypress(self, event):
         #handle the standard keypress events

#child frame
     def OnKeypress(self, event):
         self.parent.OnKeyPress(event)


Get that event to the keypress handler, no matter what the cost *wink*.
Another option would be to do the following:

#child frame
     def OnKeypress(self, event):
         a = event.Copy()
         wxPostEvent(self.parent, a)


I hope this helps,
  - Josiah



More information about the Python-list mailing list