Text¶
Abstraction of text creation. Depending of the selected backend, the text rendering can be more or less accurate.
New in version Starting: to 1.0.7, the LabelBase don’t generate any texture is the text have a width <= 1.
- class kivy.core.text.LabelBase(**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: list, 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: int, default to None
If it’s a integer, it will set padding_x and padding_y
- padding_x: int, default to 0
Left/right padding
- padding_y: int, default to 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 directly a ttf, 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.