3

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?

1 Answer 1

5

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().

Sign up to request clarification or add additional context in comments.

6 Comments

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.
For best conformance to different platforms' UI guidelines you should use wx.StdDialogButtonSizer which has that method; see wxpython.org/docs/api/wx.StdDialogButtonSizer-class.html
There is also wx.Button.SetDefault()... Anyway, what platform are you on, and what other controls are in the dialog?
button.SetDefault() is what you want.
I tried everything listed here, and the only thing that worked for me was button.SetDefault()
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.