Skip to content Skip to sidebar Skip to footer

Python 3 PyQt4 Updating GUI With Variables From Multiple Modules/classes

I've written a large program with nested classes/threads and multiple modules. I would now like to add a simple GUI and some Labels to display some variables. However, the variab

Solution 1:

Because wa is only set when __name__ == "__main__" and that only happens when test.py is the main file.

When you do import test, you are running another instance of the test.py file which is not the main script so it has __name__ == 'test' not __main__. So, even if wa was set, you would be changing another instance of it.

Possible solution:

You can get a reference to the __main__ module and set on the test2.py module:

On test.py:

import test2
test2.parent = sys.modules[__name__]

Now, on test2.py (do not import test but make sure test imports test2):

parent.wa.label.setText('Blablabla')

Post a Comment for "Python 3 PyQt4 Updating GUI With Variables From Multiple Modules/classes"