text_width()#

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

Examples#

example picture for text_width()
 1def setup():
 2    py5.text_size(28)
 3
 4    c = 't'
 5    cw = py5.text_width(c)
 6    py5.text(c, 0, 40)
 7    py5.line(cw, 0, cw, 50)
 8
 9    s = "Tokyo"
10    sw = py5.text_width(s)
11    py5.text(s, 0, 85)
12    py5.line(sw, 50, sw, 100)

Description#

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

Underlying Processing 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 March 01, 2022 12:15:01pm UTC