Python

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • capture keyboard events

    1 answers - 1220 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello,
    I am trying to capture keyboard events. Here is some stripped down code
    at my attempt.
    It doesn't seem to react to key presses?
    Any help would be very appreciated!
    thnx,
    Ray Sells
    import wx
    class Frame( wx.Frame):
    def __init__( self, image = None, parent = None, id = -1,
    pos = wx.DefaultPosition,
    title = 'C++ Model Developer'):
    """Create a Frame instance and display an image."""
    wx.Frameinit__( self, parent, id, title, pos, size = ( 400, 300))
    panel = wx.Panel( self)
    panel.button = wx.Button( panel, -1, "Close", pos = ( 100, 100))
    self.Bind( wx.EVT_BUTTN, ButtonClick)
    self.Bind( wx.EVT_KEY_DWN, Key)
    def ButtonClick( self, event):
    print "Button clicked!"
    def Key( self, event):
    k = event.GetKeyCode()
    print "key code is", k
    class App( wx.App):
    def Init( self):
    self.frame = Frame()
    self.frame.Show()
    self.SetTopWindow( self.frame)
    return True
    def main():
    app = App( False)
    app.MainLoop()
    if __name__ == '__main__':
    main()
  • No.1 | | 555 bytes | |

    Hello Ray:

    I think your problem is that you are binding to the frame, rather than
    the button. This works for command events, such as button click, but
    not for normal events, such as key down. The solution is to use

    panel.button.Bind(wx.EVT_KEY_DWN, Key)

    instead of

    self.Bind(wx.EVT_KEY_DWN, Key)

    Not tested, but it should work.

    To unsubscribe, e-mail: wxPython-users-unsubscribe (AT) lists (DOT) wxwidgets.org
    For additional commands, e-mail: wxPython-users-help (AT) lists (DOT) wxwidgets.org

Re: capture keyboard events


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Python"

EMSDN.COM