Text

Reference for the Text class, which renders multi‑line, styled UI text with optional word‑wrapping, tags and images.

Text

Text(text='', start_tag='<', end_tag='>', ignore=True, **kwargs)

Located in ursina/text.py

Overview

Text extends Entity to display UI‑space text. It supports inline color tags, embedded images, word‑wrap, background boxes and animated reveal.

Constructor Arguments

ArgumentTypeDefaultDescription
textstr''Initial string, may include tags like <red>…<default>.
start_tagstr'<'Opening delimiter for inline tags.
end_tagstr'>'Closing delimiter for inline tags.
ignoreboolTrueIf False, input events reach this entity.
**kwargsanyAny other Entity attributes (position, color, parent, etc).

Class Fields

NameTypeDefaultDescription
Text.sizefloat0.025Base character size
.sizefloatText.sizeEffective character size
.parentEntitycamera.uiUI‑space parent
.shaderanyNoneShader applied to text mesh
.text_nodeslist[]Internal mesh objects for each character/tag
.imageslist[]Embedded image entities
.origintuple(-.5, .5)Anchor at top‑left
.fontFontText.default_fontFont used
.resolutionintText.default_resolutionCharacter mesh resolution
.use_tagsboolTrueEnable inline tags
.line_heightfloat1Multiplier between lines
.text_colorsdict{'default': color.text_color}Map tag→color
.scale_overridefloat1Manual scale multiplier
.appear_sequenceanyNoneCreated by appear() for reveal animation

Properties

PropertyDescription
.textGet or set the full string including tags.
.colorDefault text color.
.widthWidth of the widest line.
.heightTotal height of all lines.
.linesList of lines after wrap.
.wordwrapWrap text after N characters when > 0.
.backgroundBackground box entity if created.

Methods

MethodDescription
text(text)Change the displayed string, rebuilding meshes.
create_text_section(text, tag='', x=0, y=0)Internal: build meshes for a substring or image tag.
align()Adjust positions of text nodes based on .origin, .line_height, .wordwrap.
create_background(padding=size*2, radius=size, color=color.black66)Add a background quad behind text.
appear(speed=0.025)Animate text reveal one character at a time.
get_width(string, font=None)Return width in world units for string.

Example Usage

from ursina import *

app = Ursina()

descr = '''\
<red>Rainstorm<default>
Summon a storm to deal 5 <blue>water<default> damage.
Lasts for 4 rounds.
'''

# scale resolution to match Text.size
Text.default_resolution = 1080 * Text.size

# create a wrapped text box
test = Text(text=descr, wordwrap=30)

def input(key):
    if key == 'a':
        test.text = '<default><image:file_icon> <red><image:file_icon> test'
    if key == 'c':
        test.text = ''

window.fps_counter.enabled = False
print('width of "yolo":', Text.get_width('yolo'))

app.run()