Problems with capturing KEY events in Linux Ubuntu

As suggested I made a simple example to show my problem. The problem is
that key events are not captured on my Linux system. (Ubuntu). Windows
and Apple OS X work fine. Seems like it must be a simple fix because
this is so basic. For the example below, key presses are ignored and I
never get into the OnKeyDown routine. Sorry in advance if this is an
obvious problem. I'm still scratching my head.

import wx

class vptFrame(wx.Frame):
    def __init__(self, parent=None, id=-1):

        wx.Frame.__init__(self,None,id,'test bind')
        # Bind Keys
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

    def OnKeyDown(self,event):
        """
        key press handler
        """
        wx.MessageBox('key down')
        event.Skip()
        
def main():
    app = wx.PySimpleApp()
    frame = vptFrame()
    frame.Show(True)
    app.MainLoop()

if __name__ == '__main__':
    main()

Many Thanks!
Michael

Hello,

Try using the WANTS_CHARS style flag and see if it helps.

···

On Wed, Dec 10, 2008 at 10:00 AM, michael@virtualpianist.com wrote:

As suggested I made a simple example to show my problem. The problem is

that key events are not captured on my Linux system. (Ubuntu). Windows

and Apple OS X work fine. Seems like it must be a simple fix because

this is so basic. For the example below, key presses are ignored and I

never get into the OnKeyDown routine. Sorry in advance if this is an

obvious problem. I’m still scratching my head.

import wx

class vptFrame(wx.Frame):

def __init__(self, parent=None, id=-1):



    wx.Frame.__init__(self,None,id,'test bind')

    # Bind Keys

    self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)



def OnKeyDown(self,event):

    """

    key press handler

    """

    wx.MessageBox('key down')

    event.Skip()

def main():

app = wx.PySimpleApp()

frame = vptFrame()

frame.Show(True)

app.MainLoop()

if name == ‘main’:

main()

Many Thanks!

Michael


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

michael@virtualpianist.com wrote:

As suggested I made a simple example to show my problem. The problem is
that key events are not captured on my Linux system. (Ubuntu). Windows
and Apple OS X work fine. Seems like it must be a simple fix because
this is so basic. For the example below, key presses are ignored and I
never get into the OnKeyDown routine. Sorry in advance if this is an
obvious problem. I'm still scratching my head.

Key and Char events are only sent to the widget that has the focus, and frames can't have the focus on wxGTK. Put some other widget in the frame and explicitly give it the focus with SetFocus.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!