Skip to main content

PyRect is a simple module with a Rect class for Pygame-like rectangular areas.

This module is like a stand-alone version of Pygame’s Rect class. It is similar to the Rect module by Simon Wittber, but compatible with both Python 2 and 3.

Currently under development, though the basic features work.

Installation

pip install pyrect

Quickstart Guide

First, create a Rect object by providing the XY coordinates of its top-left corner, and then the width and height:

>>> import pyrect
>>> r = pyrect.Rect(0, 0, 10, 20)

There are several attributes that are automatically calculated (they have the same names as Pygame’s Rect objects):

>>> r.width, r.height, r.size
(10, 20, (10, 20))
>>> r. left
0
>>> r.right
10
>>> r.top
0
>>> r.bottom
20
>>> r.center
(5, 10)
>>> r.topleft
(0, 0)
>>> r.topright
(10, 0)
>>> r.midleft
(0, 10)

Changing these attributes re-calculates the others. The top-left corner is anchored for any growing or shrinking that takes place.

>>> r.topleft
(0, 0)
>>> r.left = 100
>>> r.topleft
(100, 0)
>>> r.topright
(110, 0)
>>> r.width = 30
>>> r.topright
(130, 0)

Rect objects are locked to integers, unless you set enableFloat to True:

>>> r = pyrect.Rect(0, 0, 10, 20)
>>> r.width = 10.5
>>> r.width
10
>>> r.enableFloat = True
>>> r.width = 10.5
>>> r.width
10.5
>>> r2 = pyrect.Rect(0, 0, 10.5, 20.5, enableFloat=True)
>>> r2.size
(10.5, 20.5)

Rect Attributes

Rect objects have several attributes that can be read or modified. They are identical to Pygame’s Rect objects:

x, y

top, left, bottom, right

topleft, bottomleft, topright, bottomright

midtop, midleft, midbottom, midright

center, centerx, centery

size, width, height

w, h

There are a couple other attributes as well:

box (a tuple (left, top, width, height))

area (read-only)

perimeter (read-only)

Release files for PyRect 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyRect 0.2.0
File Size Uploaded
PyRect-0.2.0.tar.gz 17.2 kB Details

Release files / PyRect-0.2.0.tar.gz

Download URL PyRect-0.2.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f65155f6df9b929b67caffbd57c0947c5ae5449d3b580d178074bffb47a09b78
BLAKE2b-256 checksum
How to use checksums
cb042ba023d5f771b645f7be0c281cdacdcd939fe13d1deb331fc5ed1a6b3a98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page