Py5Font.width()#

Get the width of a character in this font.

Examples#

example picture for width()
 1def setup():
 2    font_size = 45
 3    font = py5.create_font('DejaVu Sans', font_size, True, 'py5')
 4    py5.text_font(font)
 5
 6    x = 10
 7    py5.text('py5', x, py5.height / 2)
 8    py5.line(x, 0, x, py5.height)
 9
10    for c in list('py5'):
11        x += font.width(c) * font_size
12        py5.line(x, 0, x, py5.height)
13
14    py5.println(font.width('x'))

Description#

Get the width of a character in this font. The value is based on a font of size 1. Multiply it by the font size to get the horizontal space of the character.

This will return 0 if the character is not in the font’s character set.

Underlying Processing method: PFont.width

Syntax#

width(c: chr, /) -> float

Parameters#

  • c: chr - single character

Updated on November 12, 2021 11:30:58am UTC