Capturing enter key pressed event for AquaButton

Hi all,

I am a little confused about wx.EVT_KEY_UP and wx.EVT_KEY_DOWN events.

In my application, I have a simple login page having text controls for entering username, password and a login button(which is an AquaButton)

I want to simulate the event when login button is clicked with the pressing of Enter key.

I binded the loginbutton to the following events.

wx.EVT_BUTTON (when user clicks Login button)

wx.EVT_KEY_DOWN (when user presses Enter key)

But I am not able to capture the Enter key pressed event.

But for a normal wx.Button it works but need to press Enter key for about 2-3 times for the event to occur.

loginbutton = wx.lib.agw.aquabutton.AquaButton(self.panel, -1,label=“Login”)

    self.panel.Bind(wx.EVT_BUTTON, self.OnSubmit, loginbutton)

    self.panel.Bind(wx.EVT_KEY_DOWN, self.onEnterKeyPressed, loginbutton)

    def onEnterKeyPressed(self,event):

        keycode = event.GetKeyCode()

        print "you pressed enter", keycode

        if keycode == wx.WXK_RETURN:

            self.OnSubmit()

   def OnSubmit(self,event):

    ## does the credential matching job

Kindly help.

Thanks in advance,

The above code will only action the enter button when the button has
focus, this is probably why you need to press enter several times,
(if a text control for login has focus but is not a type that “needs
enter” then the default action will move you on to the next tab
stop. Assuming that this page is a dialogue all you need to do is
either give your login button an id of wx.ID_OK or to call
SetAffermativeId in the constructor. Alternatively, and if it is
not a dialogue, you will need to remove the loginbutton parameter on
the second bind an call skip if the key is not Return.

···

On 21/06/2012 7:48 PM, Spondita wrote:

Hi all,

    I am a little confused about wx.EVT_KEY_UP and

wx.EVT_KEY_DOWN events.

    In my application, I have a simple login page having text

controls for entering username, password and a login
button(which is an AquaButton)

    I want to simulate the event when login button is clicked

with the pressing of Enter key.

I binded the loginbutton to the following events.

wx.EVT_BUTTON (when user clicks Login button)

wx.EVT_KEY_DOWN (when
user presses Enter key)

But I am not able to capture the Enter key pressed event.

    But for a normal wx.Button it works but need to press Enter

key for about 2-3 times for the event to occur.

      loginbutton =

wx.lib.agw.aquabutton. AquaButton(self.panel,
-1,label=“Login”)

self.panel.Bind(wx.EVT_BUTTON, self.OnSubmit, loginbutton)

self.panel.Bind(wx.EVT_KEY_DOWN, self.onEnterKeyPressed,
loginbutton)

def onEnterKeyPressed(self,event):

                  keycode =

event.GetKeyCode()

                  print "you pressed enter",

keycode

                  if keycode ==

wx.WXK_RETURN:

            self.OnSubmit()
   def OnSubmit(self,event):
              ## does the credential matching

job

Kindly help.

Thanks in advance,

  To unsubscribe, send email to

or visit

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en