Text Markup¶
New in version 1.1.0.
We provide a simple text-markup for inline text styling. The syntax look the same as the BBCode.
A tag is defined as [tag], and might have a closed tag associated: [/tag]. Example of a markup text:
[b]Hello [color=ff0000]world[/b][/color]
The following tags are availables:
- [b][/b]
- Activate bold text
- [i][/i]
- Activate italic text
- [font=<str>][/font]
- Change the font
- [size=<integer>][/size]
- Change the font size
- [color=#<color>][/color]
- Change the text color
- [ref=<str>][/ref]
- Add an interactive zone. The reference + all the word box inside the reference will be available in MarkupLabel.refs
- [anchor=<str>]
- Put an anchor in the text. You can get the position of your anchor within the text with MarkupLabel.anchors
If you need to escape the markup from the current text, use kivy.utils.escape_markup().
- class kivy.core.text.markup.MarkupLabel(*largs, **kwargs)¶
Bases: kivy.core.text.LabelBase
Markup text label.
See module documentation for more informations.
- anchors¶
Get the position of all the [anchor=...]:
{ 'anchorA': (x, y), 'anchorB': (x, y), ... }
- markup¶
Return the text with all the markup splitted:
>>> MarkupLabel('[b]Hello world[/b]').markup >>> ('[b]', 'Hello world', '[/b]')
- refs¶
Get the bounding box of all the [ref=...]:
{ 'refA': ((x1, y1, x2, y2), (x1, y1, x2, y2)), ... }