2

I m working on a python project currently, It is a application which don not interact with internet.GUI is being dine with wxpython. Is there code available in python which can simulate button click.

3
  • Please add more information. What have you tried so far? Have you searched for solutions? I think you are not the first one with this problem. But that's just a wild guess. Commented Apr 21, 2015 at 6:23
  • 1
    possible duplicate of How to programmatically generate an event in wxPython Commented Apr 21, 2015 at 6:32
  • @Alex Yeah i have searched online, there was no such example or codes available. There are some which solve the issues for the webpages and online games like pybots. Haven't tried much, just want to hack in our own application where i can simulate the button click which opens up a frame. There are various functions available in wxpython for button object but for none of them the proper documentation available to go forward. Thank you Commented Apr 21, 2015 at 7:51

1 Answer 1

6

I depends on what you really need it to do. Do you just want cause the same code to be executed as would be done when the user clicks the button? Or do you need to have a real system level mouse event occur on the native UI button as if there was a real user doing it?

For the former you just need to cause the event handler function to be called from wherever you need it to be done. You can create a matching event object and use wx.PostEvent as suggested, or simply call the event handler method directly. Or for a little bit better programming style, refactor and move the guts of the event handler to a separate function and call it from the event handler and also wherever else you need to simulate the effects of clicking the button.

For having real system level events being sent to the native widget there is the wx.UIActionSimulator class, which can be used to simulate the mouse or keyboard at a lower level than posting wx events, so the UI behaves exactly the same as if there was a real user doing it. I would guess that 95% of the time that this is overkill for cases like what you describe, and also more complex than the above, but it's there if you really need it.

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

Comments

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.