text_width()

Calculates and returns the width of any character or text string.

Examples

example picture for text_width()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def setup():
    py5.text_size(28)

    c = 't'
    cw = py5.text_width(c)
    py5.text(c, 0, 40)
    py5.line(cw, 0, cw, 50)

    s = "Tokyo"
    sw = py5.text_width(s)
    py5.text(s, 0, 85)
    py5.line(sw, 50, sw, 100)

Description

Calculates and returns the width of any character or text string.

Underlying Java method: textWidth

Syntax

text_width(c: chr, /) -> float
text_width(chars: List[chr], start: int, length: int, /) -> float
text_width(str: str, /) -> float

Parameters

  • c: chr - the character to measure

  • chars: List[chr] - the character to measure

  • length: int - number of characters to measure

  • start: int - first character to measure

  • str: str - the String of characters to measure

Updated on September 11, 2021 16:51:34pm UTC