Skip to content

Rect

The Rect class represents an SVG rectangle element. It supports setting the position and provides properties for width and height.

Info

This class inherits from SvgElement.

pydreamplet.core.Rect

Rect(**kwargs)

Initializes a new rectangle. If pos is provided, it sets the top-left corner.

Parameters

  • **kwargs: Attributes for the rectangle, including pos (a Vector) and other properties (e.g., width, height).
from pydreamplet import SVG, Rect, Vector

svg = SVG(200, 200)
svg.append(
    Rect(
        pos=Vector(50, 50),
        width=100,
        height=100,
        fill="#a00344",
    )
)

Example

pos

Getter: Returns the position (top-left corner) as a Vector.

Setter: Updates the position.

print(rect.pos)
rect.pos = Vector(20, 20)

width

Returns the width of the rectangle.

height

Returns the height of the rectangle.