Press enter key trigger an OK button?

Quoting "S. D. Rose" <s_david_rose@hotmail.com>:

No, I actually want to have pressing enter in the text control to actually
trigger the login process, not to set the button to be focused so that
pressing enter a second time, it will be triggered ...

As far as I know it does (at least on WinXP).

The example program will execute the test method when enter is pressed on the
TextCtrl.

# example wxButton.SetDefault() method
# excuse the bad style
import wx

def test(event):
   global frame
   frame.Destroy()

if __name__ == '__main__':
   global frame
   app = wx.PySimpleApp()
   frame = wx.Frame(None, -1, "Test")
   panel = wx.Panel(frame)
   text = wx.TextCtrl(panel, -1, "", pos=(10, 10))
   btn = wx.Button(panel, -1, "Test", pos=(10, 30))
   frame.Bind(wx.EVT_BUTTON, test, btn)
   btn.SetDefault()
   frame.Show(True)
   app.MainLoop()

Regards,

Ray Smith

Exactly what I want to do! Thank you John. Ray, thank you also for your
assistance!!!

-Dave

"John Fouhy" <john@fouhy.net> wrote in message
news:5e58f2e40605311938h39c938c6p2d208d14957bf2f3@mail.gmail.com...

···

On 01/06/06, S. D. Rose <s_david_rose@hotmail.com> wrote:

If this clarifies a bit what I'm trying to do ....

class LoginDialog2(wxGUI.LoginDialog2):
    def __init__(self, *args, **kwds):

        self.loginBitmap = r'logo/CheckBuster Login Logo.bmp'
        # begin wxGlade: AppFrame.__init__
        wxGUI.LoginDialog2.__init__(self, *args, **kwds)
        # end wxGlade dbUserName

        self.dbPasswd.Bind(wx.EVT_CHAR, self.OnPasswd )

    def OnPasswd(self, event):
        if event.GetKeyCode() == wx.WXK_RETURN:
            print 'Enter Pressed'
            self.Ok_button.SetDefault()

I'm not familiar iwth wxGlade or wxGUI, but I think this may work in
standard wx:

   def OnPasswd(self, event):
       if event.GetKeyCode() == wx.WXK_RETURN:
           print 'Enter Pressed'
           self.EndModal(wx.ID_OK)

EndModal is documented here:
http://www.wxwindows.org/manuals/2.6.3/wx_wxdialog.html#wxdialogendmodal

Also, TextCtrls can generate a special event for the Enter key. It's
not likely to make much of a difference, but it may be "preferred" for
style reasons (anyone know for sure?).

You would need to specify the wx.TE_PROCESS_ENTER style when creating
your password TextCtrl, and then catch the wx.EVT_TEXT_ENTER event.

HTH!

--
John.