[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Rect attributes question



I am doing some writing about Python, and I want to make sure that what I am about to write is correct.

As an example, in the following, I am creating a pygame rect, then printing the left and right attributes.

>>> myRect = pygame.Rect(10, 10, 30, 30)
>>> print(myRect.left, myRect.right)
10 40

Then, I explicitly change the left attribute, and print the left and right again.
>>> myRect.left = 50
>>> print(myRect.left, myRect.right)
50 80

This all works fine, just what I expect.  

But I'm curious about the implementation of this.  When a line like this runs:

myRect.left = 50

is this implemented with a property of a rect object, so it's actually calling a method with a property decorator?  This would seem to be the case because I am changing just one value (left), but other values also change along with it - not only the right, but .center, etc.

I have never looked at the pygame source code (maybe someone can tell me where the code that implements rects can be found).  But for now, I would just like to know if these attributes (left, right, top, bottom, width, height, etc.) are all implemented as Python property decorators.

Thanks,

Irv