Skip to content

Update a widget value from another script? #1325

Answered by freakboy3742
svandragt asked this question in Q&A
Discussion options

You must be logged in to vote

There will only ever be a single App instance in a running executable, and the app tracks that instance as App.app; so the following will do what you need:

import toga

def example():
    toga.App.app.add_log('Hello World')

However, generally speaking, I'd advise against relying on App.app. It works (and needs to exist for a variety of reason); but as a general matter of code style, if there's "another part of your app" that needs to know about the app, then it should be constructed and configured with a reference to the app (or, preferably, with a reference to a common data source that, when updated, is reflected in the app's GUI).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by svandragt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants