friderik
friderik

Reputation: 137

Handling multiple objects of a class

I'm doing some exercises with drawing using PyQt. Basically, I want to create some points that float around a widget space. So far, I managed to create a class with points' x and y coordinates and how this point bounces around my widget scene. My code draft:

Class Points:
    def __init__(self):
        self.x = #something
        self.y = #something

    def float(self):
        angle = random.random() #some angle
        while (True):
            #everything to make my point float around

My problem doesn't lie in PyQt itself, but in a way that objects work. I want to create multiple point that float around in my widget scene. How would I create multiple points (multiple objects of the same class) that float around independently? If I'd create a list of newly created points in my Points class, they'd all have the same data but I want every point to have different data.

Thanks!

Upvotes: 0

Views: 87

Answers (1)

Guimoute
Guimoute

Reputation: 4629

I would remove the while(True) from the class and add it in the main program.

class Points:
    def __init__(self):
        self.x = #something
        self.y = #something

    def float_once(self):
        angle = random.random() #some angle
        #everything to make my point float around

A = Points()
B = Points()
while True:
    A.float_once()
    B.float_once()

Upvotes: 1

Related Questions