WxButton

L

LutherRevisited

I have a simple application in a Frame, in it I have a button that I want to
press when I hit enter. How can I do this? I know with textctrl's you have
the EVT_TEXT_ENTER event to do things for you when enter is pressed, can I do
the same with a button. I know in WxWidgets for C++ you can put it in a
WxDialog and it will do all that anyway, but my version of WxPython doesn't
have that
 
M

M.E.Farmer

ok this is slightly confusing , so I am just gonna throw out some ides.
You could define an accelerator table and just bind wxACCEL_NORMAL,
and WXK_RETURN to an id number.
then set an event handler to operate your button(more on that later).
Or you can set an event to just look for a certain key :
Declare this event.

py> EVT_KEY_DOWN(self, self.OnKeyPressed)

And do something like this.

py> def OnKeyPressed(self, event):
.... key = event.KeyCode()
.... if key == WXK_RETURN:
.... BtnPressCode()

Ok now the button thing what are you wanting just to activate the
button or to toggle the button or.?
There are many buttons types and they have very different methods!
I will leave that code up to you ( just do a google search for wxButton
or wxToggleButton or even wxBitmapButton and many more just search the
docs they are very helpful, and always this is covered somewhere in the
wx demo ;)
Hth,
M.E.Farmer
 
L

LutherRevisited

That's kindof where I want to go, how can I detect whether or not my button has
focus. Basically I only want to press it with enter if it has focus.
 
K

Kartic

Have you explored the wxPython Demo application? It is a pretty helpful
learning tool.
 
L

LutherRevisited

Yes I have actually, I still can't figure out how to have my application detect
if a control has focus. If I could, I could just use the keydown event with an
if statement to push my button when it has focus and enter is pressed.
 
L

LutherRevisited

Disregard all my posts on this thread, I just downloaded Boa-constructor which
has WxDialogs making my life so much simpler. Thanks for all the help though.
I was using SPE which uses WxGlade to make gui's, which isn't so bad if you're
familiar with the way Java works on GUIs that is, but Boa-Constructor is really
cool!
 
M

M.E.Farmer

LutherRevisited said:
Yes I have actually, I still can't figure out how to have my application detect
if a control has focus. If I could, I could just use the keydown event with an
if statement to push my button when it has focus and enter is
pressed.

I am gonna try and explain how to fish ;)
Lets start with what we want to know :
What methods does wx.Button have, how do I find out?
0) Do a search for wx.Button on Google.
1) Consult the very extensive documentation available from
wxPython.org
if it didn't come with your distro.
2) Consult the Demo that comes with wxPython ( I see you have
tried )
3) Open an interpreter and try print dir(mybutton)
and see what it gives you......very informative!
Actually find out what it your object really supports,
even better than out of date docs.
4) Search a newsgroup for wx.Button or wxButton
5) Ask a newsgroup

Now on to some hints into the workings of wx.
Just about everything in wx inherits from something ( usually window ).
That means you have to look at all the bases to see what all is
available in an object. wx.Button has window as a parent, that means we
can simply use window's methods ,like SetFocus().
Always look at the bases to figure out what you have available you can
be surprised what an object is capable of.
I still dont know what you are trying to achieve.
Are you using regular buttons or toggles or bitmaps or who knows, it
matters.
I am going to mention this if you just want to activate the button that
has focus using the return key than it already works like that just tab
to the button and press return.
If you want to make a button focused by default you can use
SetDefault()
Sounds like you are trying to hard to do something simple, try less.
Hth,
M.E.Farmer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top