python - wxpython can't capture EVT_KEY_DOWN enent -


i can't capture evt_key_down event. can capture evt_key_up.
python version : 2.7.3
wxpython version : 2.8.12.1 (gtk2-unicode)
system info: mint 14 nadia , linux 3.5.0-17-generic(x86_64)
following code

#!/usr/bin/env python  import sys, os import wx class  winframe(wx.frame):     def __init__(self, parent, title):         super(winframe, self).__init__(parent,                                         title=title,                                        size=(400,400))         self.panel = wx.panel(self,-1, size=(400,400))         self.panel.bind(wx.evt_key_down, self.onkeydown)         self.panel.bind(wx.evt_key_up, self.onkeyup)     def onkeyup(self, event):         print 'up'      def onkeydown(self, event):         print 'down'  class picsampleapp(wx.app):     def __init__(self):         super(picsampleapp, self).__init__(0)      def createframe(self):         self.frame = winframe(none, "test")         self.frame.show(true)         self.settopwindow(self.frame)   app = picsampleapp() app.createframe() app.mainloop() 

i've had problems capturing wx.evt_key_down , wx.evt_key_up. explanation of why bit on head, know switching evt_char_hook trick me. try this:

#!/usr/bin/env python  import sys, os import wx class  winframe(wx.frame):     def __init__(self, parent, title):         super(winframe, self).__init__(parent,                                         title=title,                                        size=(400,400))         self.panel = wx.panel(self,-1, size=(400,400))         self.panel.bind(wx.evt_char_hook, self.onkeypress)      def onkeypress(self, event):         keycode = event.getkeycode()         if keycode == wx.wxk_down:             print 'down'         elif keycode == wx.wxk_up:             print 'up'  class picsampleapp(wx.app):     def __init__(self):         super(picsampleapp, self).__init__(0)      def createframe(self):         self.frame = winframe(none, "test")         self.frame.show(true)         self.settopwindow(self.frame)  app = picsampleapp() app.createframe() app.mainloop() 

you might want put event.skip() @ bottom of onkeypress if want event continue propagating.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -