Skip to content

UI Text

Text

Text(
    scene: "Scene",
    parent: Element,
    *,
    text: str,
    color: ColorRGBA,
    font: pygame.font.Font,
    position: tuple[Union[int, float], Union[int, float]],
    anchor: Anchor = Anchor.TOP_LEFT
)

Bases: Element

User-Interface Text.

Create a new user interface text.

PARAMETER DESCRIPTION
scene

The scene to interface this instance with.

TYPE: Scene

parent

Any ~Element-like object to make the parent of this instance.

TYPE: Element

text

The text that will be shown.

TYPE: str

color

The color of the foreground (text).

TYPE: ColorRGBA

font

The font to render the text as.

TYPE: pygame.font.Font

position
  • The X and Y values for the pixels in which this element will be placed.
  • If int they represent absolute pixel values, otherwise (float) will represent scaled pixel values.

TYPE: tuple[int | float, int | float]`

anchor

The chosen area of this element to place at the position provided.

TYPE: Anchor DEFAULT: Anchor.TOP_LEFT

RAISES DESCRIPTION
TypeError
  • Provided text isn't a str.
  • Provided font isn't a pygame.font.Font.
  • Provided position X and Y values aren't int or float.
  • Provided anchor isn't an Anchor object.
ValueError
  • If any value of position is float and is not between 0 and 1.
  • If values of position are not two values in length.

text_render instance-attribute

text_render: pygame.Surface = None

Rendered internal text object that is updated every change - Usable with OpenGL as well.

color_text property writable

color_text: ColorRGBA

The color of the text.

text property writable

text: str

The text being shown in this element.

enabled instance-attribute

enabled: bool = True

If this element is enabled.

children property

children: tuple[Element]

All children of this element.

parent property

parent: Element

The parent of this element.

set_font

set_font(font: pygame.font.Font) -> None

Set the font of the rendered text.

PARAMETER DESCRIPTION
font

The font to set the text to render as.

TYPE: pygame.font.Font

RAISES DESCRIPTION
TypeError

If the provided font is not pygame.font.Font

set_transform

set_transform(
    *,
    anchor: Anchor = None,
    position: tuple[
        Union[int, float], Union[int, float]
    ] = None
) -> None

Set the transform (position, size, anchor) attributes of this element.

PARAMETER DESCRIPTION
anchor

If provided, change the anchor point of this element.

TYPE: Anchor DEFAULT: None

position

If provided, change the position of this element - int for absolute, float for scaled.

TYPE: tuple[int | float, int | float] DEFAULT: None

Info

anchor, position, or size are optional, but one has to be specified.

RAISES DESCRIPTION
TypeError
  • Provided anchor isn't an Anchor object.
  • Provided position X and Y values aren't int or float.
ValueError
  • If none of the parameters above are provided.
  • If any value of position is float and is not between 0 and 1.

tween

tween(
    position: Iterable[Union[int, float]],
    duration: float,
    easing: Callable[[float], float] = Easing.LINEAR,
) -> None

Tween/animate this element to an end state over a period of time.

PARAMETER DESCRIPTION
position

The end position to reach.

TYPE: typing.Iterable[int | float]

duration

The time in which it'll take to animate this element in seconds.

TYPE: float

easing

The easing function to use when animating.

TYPE: typing.Callable[[float], float] DEFAULT: Easing.LINEAR

RAISES DESCRIPTION
TypeError
  • If position is not an iterable object.
  • If duration is not int or float.
ValueError
  • If position doesn't contain only two values.
  • If position or duration don't contain int or float values.

add_child

add_child(child: Element) -> None

Add a child to this element.

PARAMETER DESCRIPTION
child

The child to add to this element.

TYPE: Element

RAISES DESCRIPTION
TypeError

If the child provided is not an Element.

remove_child

remove_child(child: Element) -> None

Remove a child from this element.

PARAMETER DESCRIPTION
child

The child to remove from this element.

TYPE: Element

RAISES DESCRIPTION
TypeError

If the child provided is not an Element.

render_opengl

render_opengl() -> None

Forceably render this element to the screen using a custom-implemented OpenGL rendering program.

request_render

request_render() -> None

Render this element and it's children to the screen, if enabled.

set_tween_callback

set_tween_callback(
    callback: Callable[[None], None],
) -> None

Set a callback method for when this element finishes tweening/animating.