QUICK REFERENCE
Text
Display and update labels with fonts, sizing, alignment, and decoration.Creating text
A Text object draws a string from the top-left of its measured text block. Set its content, position, color, typography, rotation, and visibility when it is created.
Text(screen, text, x, y, color=Color("black"), font="Arial", size=16, align="left", bold=False, italic=False, underline=False, strikethrough=False, rotation=0, visible=True)Create a text label at an x and y coordinate.
Text(screen, text, location, ...)Create the same label from a Location instead of separate coordinates.
title = Text(
screen, "Space explorer", 30, 24,
Color("navy"), size=28, bold=True
)instructions = Text(
screen,
"Arrow keys: move\nSpace: pause",
Location(30, 75),
Color("gray"),
size=14,
)Content & measured size
Change a label without recreating it. pyDraw remeasures the text whenever its content or font styling changes, so width and height always describe the current text block.
text.text(value=None)Read the current string, or replace it. Use \n inside a string to start another line.
text.width() · text.height()Return the measured dimensions of the entire text block.
text.size(value=None)Read or change font size; changing it also updates measured dimensions.
text.update()Explicitly remeasure and refresh the label when needed.
score = 0
score_text = Text(screen, "Score: 0", 20, 20)
score += 1
score_text.text(f"Score: {score}")message = Text(screen, "Level complete!", 80, 60, size=24)
panel = Rectangle(
screen, message.x() - 12, message.y() - 10,
message.width() + 24, message.height() + 20,
Color("light yellow")
)
message.front()Position & alignment
Move the text block with its location methods. Alignment controls how each line sits inside the widest line of a multiline block; it does not change the object's x/y anchor.
text.x(value=None) · text.y(value=None) · text.location()Read the top-left anchor, or replace either coordinate.
text.move(dx, dy) · text.moveto(x, y)Move by an offset or move to an absolute position.
text.center() · text.center(x, y)Read the center of the measured block or move it to a new position.
text.align(value=None)Read or set multiline alignment to "left", "center", or "right".
heading = Text(
screen, "PLAYER ONE\nready", 0, 30,
size=26, align="center"
)
heading.center(x=screen.width() / 2)heading.move(0, 20)
heading.moveto(40, 90)Font, color & decoration
Typography can be changed at any time. Style methods act as both getters and setters, which makes temporary states such as highlighted or completed labels straightforward.
text.color(value=None)Read or change the text Color.
text.font(value=None) · text.size(value=None)Read or change the font family and pixel size.
text.bold(value=None) · text.italic(value=None)Read or toggle font weight and italic styling.
text.underline(value=None) · text.strikethrough(value=None)Read or toggle either line decoration.
status = Text(screen, "Connected", 20, 20)
status.color(Color("green"))
status.bold(True)
status.size(18)task = Text(screen, "Collect the key", 20, 55)
task.strikethrough(True)
task.color(Color("gray"))Rotation & direction
Text rotates around the center of its measured block. It can also face a target or move along its current heading like other Renderables.
text.rotation(angle=None) · text.rotate(angle_difference)Read or set an absolute rotation, or turn by a relative number of degrees.
text.lookat(object_or_location) · text.angleto(object_or_location)Face a target or measure the required turn.
text.forward(distance) · text.backward(distance)Move along the label's current heading.
label.rotation(20)
label.rotate(5)label.lookat(screen.mouse())
label.forward(3)Geometry & copies
Treat a Text object as a rotated rectangular block for placement and collision checks, or clone it to create another independently styled label.
text.vertices() · text.bounds()Read the rotated corners or axis-aligned bounds of the measured block.
text.contains(point) · text.overlaps(renderable)Test a point or another Renderable against the text block.
text.distance(object_or_location)Measure from the center of the text block to another object or point.
text.transform()Return (measured width, measured height, rotation).
text.clone()Create an active copy on the same Screen with the same content and style.
def mousedown(location):
if label.contains(location):
label.bold(not label.bold())shadow = label.clone()
shadow.move(3, 3)
shadow.color(Color("light gray"))
shadow.back()Visibility, order & lifecycle
Hide a label without removing it, control its drawing order, or attach a Pen when its top-left anchor should leave a trail.
text.visible(value=None)Read or change whether the label is drawn.
text.front() · text.back()Move the label to the front or back of the drawing order.
text.remove()Detach the label from its Screen; use screen.add(text) to restore it.
text.pen(color=Color("black"), width=2, top=False)Start a Pen that follows later movement of the label's x/y anchor.
status.visible(False)
status.visible(True)
status.front()status.remove()
screen.add(status)