WxButton

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • LutherRevisited

    #1

    WxButton

    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.E.Farmer

    #2
    Re: WxButton

    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(se lf, self.OnKeyPress ed)

    And do something like this.

    py> def OnKeyPressed(se lf, 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

    Comment

    • LutherRevisited

      #3
      Re: WxButton

      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.

      Comment

      • Kartic

        #4
        Re: WxButton

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

        Comment

        • LutherRevisited

          #5
          Re: WxButton

          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.

          Comment

          • LutherRevisited

            #6
            Re: WxButton

            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!

            Comment

            • M.E.Farmer

              #7
              Re: WxButton

              LutherRevisited wrote:[color=blue]
              > Yes I have actually, I still can't figure out how to have my[/color]
              application detect[color=blue]
              > if a control has focus. If I could, I could just use the keydown[/color]
              event with an[color=blue]
              > if statement to push my button when it has focus and enter is[/color]
              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

              Comment

              Working...