views:

426

answers:

1

I am creating a custom wxPython dialog by subclassing wx.Dialog. When I press Enter while using it, (and while being focused on one of the form elements,) it just takes the focus to the next form element, while I want it to press the ok button.

How do I solve this?

+3  A: 

That should happen automatically if the button has the wx.ID_OK id. If that's impossible then the wx.StdDialogButtonSizer.SetAffirmativeButton() method could be a solution (using the StdDialogButtonSizer class will help with correct button placement and positioning on the different platforms), and there is also wx.Button.SetDefault().

mghie
I put the id as wx.ID_OK, didn't seem to affect anything. I looked for SetAffirmativeButton (in Dialog), doesn't seem to exist. There is SetAffirmativeId, tried it on the button's ID, and it didn't work.
cool-RR
For best conformance to different platforms' UI guidelines you should use wx.StdDialogButtonSizer which has that method; see http://www.wxpython.org/docs/api/wx.StdDialogButtonSizer-class.html
mghie
There is also wx.Button.SetDefault()... Anyway, what platform are you on, and what other controls are in the dialog?
mghie
XP, but it should work on them all.The other controls are RadioButtons and TextCtrls.Going to sleep now, will try your solutions tomorrow, thanks.
cool-RR
button.SetDefault() is what you want.
FogleBird
I tried everything listed here, and the only thing that worked for me was `button.SetDefault()`
cool-RR