Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to call class function from seperate class function through Threading module Python

I’m coding my own Asteroids minigame using pygame (which is extremely inefficient with multiple sprites so wanted to use threading.

How do I access a function from another class (asteroids class) through my main class (handler) class.

If my class system is backwards or doesn’t work using Threading, please explain to me how I could make it more efficient or easy to code in

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Asteroids():
    def __init__(self):
    ....
    def Update(self):
    ....

class Handler():
    def __init__(self):
    ....
    def Update_All(self):
    x = threading.Thread(target = ##Asteroids.Update()
    x.start()

thanks in advance

>Solution :

You need to create an instance of Asteroids

astroid = Astroids()
# then you can use the function in your thread
x = threading.Thread(target = astroid.Update())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading