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:

[b][/b]
Activate bold text
[i][/i]
Activate italic text
[u][/u]
Underlined text
[s][/s]
Strikethrough text
[font=<str>][/font]
Change the font
[size=<size>][/size]
Change the font size. <size> should be an integer, optionally with a unit (i.e. 16sp)
[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
[sub][/sub]
Display the text at a subscript position relative to the text before it.
[sup][/sup]
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.

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)), ... }
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.