Quick search

Table Of Contents

Text

Abstraction of text creation. Depending of the selected backend, the text rendering can be more or less accurate.

Changed in version 1.5.0: LabelBase.line_height added.

Changed in version 1.0.7: The LabelBase don’t generate any texture is the text have a width <= 1.

class kivy.core.text.LabelBase(text='', font_size=12, font_name='DroidSans', bold=False, italic=False, halign='left', valign='bottom', shorten=False, text_size=None, mipmap=False, color=None, line_height=1.0, **kwargs)

Bases: object

Core text label. This is the abstract class used for different backend to render text.

Warning

The core text label can’t be changed at runtime, you must recreate one.

New in version In: 1.0.7, the valign is now respected. This wasn’t the case before. You might have issue in your application if you never think about that before.

New in version In: 1.0.8, size have been deprecated and replaced with text_size

Parameters :
font_size: int, default to 12

Font size of the text

font_name: str, default to DEFAULT_FONT

Font name of the text

bold: bool, default to False

Activate “bold” text style

italic: bool, default to False

Activate “italic” text style

text_size: tuple, default to (None, None)

Add constraint to render the text (inside a bounding box) If no size is given, the label size will be set to the text size.

padding: float, default to None

If it’s a float, it will set padding_x and padding_y

padding_x: float, default to 0.0

Left/right padding

padding_y: float, default to 0.0

Top/bottom padding

halign: str, default to “left”

Horizontal text alignement inside bounding box

valign: str, default to “bottom”

Vertical text alignement inside bounding box

shorten: bool, defaults to False

Indicate whether the label should attempt to shorten its textual contents as much as possible if a size is given. Setting this to True without an appropriately set size will lead unexpected results.

mipmap : bool, default to False

Create mipmap for the texture

content_height

Return the content height

content_size

Return the content size (width, height)

content_width

Return the content width

fontid

Return an uniq id for all font parameters

get_extents(text)

Return a tuple with (width, height) for a text.

label

Get/Set the text

refresh()

Force re-rendering of the text

static register(name, fn_regular, fn_italic=None, fn_bold=None, fn_bolditalic=None)

Register an alias for a Font.

New in version 1.1.0.

If you’re using a ttf directly, you might not be able to use bold/italic of the ttf version. If the font is delivered with different version of it (one regular, one italic and one bold), then you need to register it and use the alias instead.

All the fn_regular/fn_italic/fn_bold parameters are resolved with kivy.resources.resource_find(). If fn_italic/fn_bold are None, fn_regular will be used instead.

render(real=False)

Return a tuple(width, height) to create the image with the user constraints.

2 differents methods are used:
  • if user don’t set width, splitting line and calculate max width + height
  • if user set a width, blit per glyph
text

Get/Set the text

text_size

Get/set the (width, height) of the contrained rendering box

usersize

(deprecated) Use text_size instead.