Text¶
- draw_text.add_text(text: str, x: int, y: int, color: int, shadow: bool, display_duration: float, layer: int = 1) int¶
Add a text element to the screen.
- Parameters:
text – Text to display.
x – X-coordinate of the text position.
y – Y-coordinate of the text position.
color – Text color. Must be created with argb(…) or taken from the Colors class.
shadow – Whether the text should be rendered with a shadow.
display_duration – How long the element remains on screen (in seconds).
layer – Rendering layer of the element. Higher layers appear above lower ones. Default is 1.
- Returns:
ID of the created element.
- draw_text.add_advanced_text(text: str, x: int, y: int, color: int, shadow: bool, display_duration: float, layer: int, matrix: Matrix) int¶
Add a text element to the screen, with additional scaling, rotation, and translation options.
Advanced version of
add_text()that allows custom transformations.- Parameters:
text – Text to display.
x – X-coordinate of the text position.
y – Y-coordinate of the text position.
color – Text color. Must be created with argb(…) or taken from the Colors class.
shadow – Whether the text should be rendered with a shadow.
display_duration – How long the element remains on screen (in seconds).
layer – Rendering layer of the element. Higher layers appear above lower ones.
matrix – Transformation matrix applied to the element (scale, rotation, translation). See
Matrix.
- Returns:
ID of the created element.
- draw_text.animate_text(_id: int, func: Callable[[TextObject], None]) None¶
Animates the text element with the given id by calling the given function every frame with the text element as the argument.
- Parameters:
_id – ID of the text element to animate.
func – Function to use to animate the text element. The function is called every frame with the text element as the argument.
- draw_text.modify_text(_id: int, func: Callable[[TextObject], None]) None¶
Modifies the text element with the given id by calling the given function once with the text element as the argument.
- Parameters:
_id – ID of the text element to modify.
func – Function to use to modify the text element. The function is called on the closest render frame.
TextObject class¶
- class draw_text.TextObject(_id: int)¶
This class represents a text element. To create a TextObject object, call the constructor with the id of the text element.
- text: str¶
Text of the text element.
- x: int¶
X-coordinate of the text.
- y: int¶
Y-coordinate of the text.
- color: int¶
Text color. Must be created by the [argb]() function or from the [Colors]() class.
- shadow: bool¶
Trueif the text has a shadowFalseotherwise.
- display_duration_modifier: float¶
Modifier to the
display_durationproperty.
- layer: int¶
Layer of the element.
- property width¶
Width of the text. This property cannot be assigned.
- property height¶
Height of the text. This property cannot be assigned.
- property display_duration¶
Time in seconds that the element will remain on screen. This property cannot be assigned, use
display_duration_modifierto change this value.
- update(_id: int)¶
Updates this TextObject with the values of the text element specified by _id.
- Parameters:
_id – ID of the text element.
- to_list() list¶
Returns a list containing all the values of this TextObject.
- Returns:
List containing all the values of this TextObject.
Example¶
1from draw_text import *
2
3add_text("Hello!", x=10, y=10, color=Colors.WHITE, shadow=True, display_duration=5, layer=1)
4add_text("Above Hello!", x=10, y=20, color=Colors.WHITE, shadow=True, display_duration=5, layer=2)
5
6add_advanced_text("I am BIG!", x=10, y=50, color=Colors.WHITE, shadow=True, display_duration=5, layer=1, matrix=Matrix().scale(2))
7
8text_id = add_text("I change colors!", x=10, y=80, color=Colors.RED, shadow=False, display_duration=5)
9
10animate_text(text_id, rainbow_animation) # Uses built-in rainbow animation