WxButton

Discussion in 'Python' started by LutherRevisited, Dec 26, 2004.

  1. 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
     
    LutherRevisited, Dec 26, 2004
    #1
    1. Advertising

  2. LutherRevisited

    M.E.Farmer Guest

    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
     
    M.E.Farmer, Dec 26, 2004
    #2
    1. Advertising

  3. 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.
     
    LutherRevisited, Dec 27, 2004
    #3
  4. LutherRevisited

    Kartic Guest

    Have you explored the wxPython Demo application? It is a pretty helpful
    learning tool.
     
    Kartic, Dec 27, 2004
    #4
  5. 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.
     
    LutherRevisited, Dec 27, 2004
    #5
  6. 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!
     
    LutherRevisited, Dec 27, 2004
    #6
  7. LutherRevisited

    M.E.Farmer Guest

    LutherRevisited wrote:
    > 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
     
    M.E.Farmer, Dec 27, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. grays
    Replies:
    1
    Views:
    297
    grays
    Jun 25, 2008
Loading...

Share This Page