Shansal
Shansal

Reputation: 1379

Call a Function in Another Frame (WxPython)

In my wxpython app, I have a parent frame and a child frame. When I click on a button inside the child frame, I want it to send some data (list, string etc.) to the parent frame, close itself, show the parent and finally call a function in the parent frame. How can I do that? (especially function calling)

Thanks in advance.

SOLVED

Upvotes: 1

Views: 1935

Answers (2)

Mike Driscoll
Mike Driscoll

Reputation: 33071

You can use pubsub to do that too: http://www.blog.pythonlibrary.org/2010/06/27/wxpython-and-pubsub-a-simple-tutorial/

Or you can just use a subclass of a Dialog instead and show it modally. Or you could use PostEvent to pass the event. There's an example here: http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

Another method that I just thought of would be to use a socket server or similar and post your data to that and have your program check the server for new data. That's pretty convoluted for this use case though.

Upvotes: 1

Velociraptors
Velociraptors

Reputation: 2030

You should have the button click generate an event containing the data. Then add an event handler to the parent frame that extracts the data from the event and calls the function. The wxPython wiki has a tutorial that covers events. The wx documentation also has an event handling overview.

Upvotes: 2

Related Questions