Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:29:05+00:00 2026-06-05T10:29:05+00:00

I’ve written a large program with nested classes/threads and multiple modules. I would now

  • 0

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 variables are scattered throughout the modules and classes.
I’m looking for a way to update these variables into the GUI without altering
the current code too much.

I have a rudimentary understanding of Pyqt4 (i will accept tkinter answers also).

I’ve tried not to use signals/emits because to my knowledge emits
must be sent from a Qthread which would mean a complete overhaul of my code, changing
classes and threads over to Qthreads. Id like to avoid needing to do this if possible.
Here is one example I’ve attempted.

test.py

class Update(Thread): 
    def __init__(self): 
        Thread.__init__(self) 
    def run(self): 

        for i in range(10): 
            time.sleep(2) 
            import test 
            wa.label.setText(str(i)) 

class MyWindow(QWidget):  
    def __init__(self, *args):  
        QWidget.__init__(self, *args) 

        self.label = QLabel(" ") 
        layout = QVBoxLayout() 
        layout.addWidget(self.label) 
        self.setLayout(layout) 

        Update1 = Update() 
        Update1.start() 
        Update1.refresh1 = 'ba' 

        self.label.setText(Update1.refresh1) 


if __name__ == "__main__":  
    app = QApplication(sys.argv)  
    wa = MyWindow()  
    wa.show()  
    sys.exit(app.exec_()) 

This code works, but my variables need to update from other modules/classes or threads. The moment I move ‘class Update’ into a new module like THIS:

test.py

import test2 


class MyWindow(QWidget):  
    def __init__(self, *args):  
        QWidget.__init__(self, *args) 

        self.label = QLabel(" ") 
        layout = QVBoxLayout() 
        layout.addWidget(self.label) 
        self.setLayout(layout) 

        Update1 = test2.Update() 
        Update1.start() 
        Update1.refresh1 = 'ba' 

        self.label.setText(Update1.refresh1) 


if __name__ == "__main__":  
    app = QApplication(sys.argv)  
    wa = MyWindow()  
    wa.show()  
    sys.exit(app.exec_()) 

test2.py #updates GUI

class Update(Thread): 
    def __init__(self): 
        Thread.__init__(self) 
    def run(self): 

        for i in range(10): 
            time.sleep(2) 
            import test 
            test.wa.label.setText(str(i)) 

I get: AttributeError: 'module' object has no attribute 'wa'

Also, I was also considering putting class Update() into a Qthread, running it from any module/class where a variable has been updated and using the emit function inside Update(). this would solve having to change my current classes/threads to be Qthreads.

If anyone knows of a simple way I could update my GUI simply by calling a class like update() an example would be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:29:07+00:00Added an answer on June 5, 2026 at 10:29 am

    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')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.