2012年6月13日 星期三

Python wxwidgets bind key 做法

class MyApp(wx.App):
    def init_frame(self):
        self.res = xrc.XmlResource('login.xrc')

        self.frame = self.res.LoadFrame(None, 'mainFrame')

        # 在此 frame 下監聽所有按鍵反應
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

        # 或綁定單一原件
        wx.EVT_KEY_DOWN(xrc.XRCCTRL(self.frame, 'userTxt'), self.OnKeyDown)

        self.frame.Show()

    def OnKeyDown(self, e):
        key = e.GetKeyCode()

        if key == wx.WXK_ESCAPE:
            print 'Event!'
        else:
            e.Skip()


用陣列綁定多個 key
python - In wxPython how do you bind a EVT_KEY_DOWN event to the whole window? - Stack Overflow




Reference :
python - wxpython capture keyboard events in a wx.Frame - Stack Overflow
Events in wxPython

self.Bind vs. self.button.Bind - wxPyWiki

Keycode Table

CharacterCodesAndKeyboards - wxPyWiki

wxPython: Catching Key and Char Events « The Mouse Vs. The Python

沒有留言:

張貼留言