Quick search

Table Of Contents

Text Markup

バージョン 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 should have a corresponding [/tag] closing tag. For example:

[b]Hello [color=ff0000]world[/color][/b]

The following tags are available:

Activate bold text
Activate italic text
Underlined text
Strikethrough text
Change the font
Change the font size. <size> should be an integer, optionally with a unit (i.e. 16sp)
Change the text color
Add an interactive zone. The reference + all the word box inside the reference will be available in MarkupLabel.refs
Put an anchor in the text. You can get the position of your anchor within the text with MarkupLabel.anchors
Display the text at a subscript position relative to the text before it.
Display the text at a superscript position relative to the text before it.

If you need to escape the markup from the current text, use kivy.utils.escape_markup().

class kivy.core.text.markup.MarkupLabel(*largs, **kwargs)[ソース]

ベースクラス: kivy.core.text.LabelBase

Markup text label.

See module documentation for more informations.


Get the position of all the [anchor=...]:

{ 'anchorA': (x, y), 'anchorB': (x, y), ... }

Return the text with all the markup splitted:

>>> MarkupLabel('[b]Hello world[/b]').markup
>>> ('[b]', 'Hello world', '[/b]')

Get the bounding box of all the [ref=...]:

{ 'refA': ((x1, y1, x2, y2), (x1, y1, x2, y2)), ... }
shorten_post(lines, w, h, margin=2)[ソース]

Shortens the text to a single line according to the label options.

This function operates on a text that has already been laid out because for markup, parts of text can have different size and options.

If text_size [0] is None, the lines are returned unchanged. Otherwise, the lines are converted to a single line fitting within the constrained width, text_size [0].

Params:lines: list of LayoutLine instances describing the text. w: int, the width of the text in lines, including padding. h: int, the height of the text in lines, including padding. margin int, the additional space left on the sides. This is in addition to padding_x.
戻り値:3-tuple of (xw, h, lines), where w, and h is similar to the input and contains the resulting width / height of the text, including padding. lines, is a list containing a single LayoutLine, which contains the words for the line.