简体   繁体   中英

Catching enter pressed event

I have problem with key pressed event in python.I have a text field and what I want to do is when that text field has focus and user presses enter button to change default behavior(which is bringing focus to next widget) and insted call some function. Here is what I did:

self.password_input.Bind(wx.EVT_KEY_DOWN, self.onKeyDown)

def onKeyDown(self, e):
    print e.GetKeyCode
    if e.GetKeyCode() == wx.WXK_RETURN:
        self.login()
    else:
        e.Skip()

But this doesnt work.Strange thing is when I put any other key instead of WXK_RETURN it will work. For example if I put if e.GetKeyCode() == wx.WXK_SPACE: it will work, it will call login() function when space is pressed...It seems only for enter it doesnt work.Anyone knows why?

On http://docs.wxwidgets.org/2.8/wx_wxtextctrl.html :

Window styles

wxTE_PROCESS_ENTER The control will generate the event wxEVT_COMMAND_TEXT_ENTER (otherwise pressing Enter key is either processed internally by the control or used for navigation between dialog controls).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM