The label widget is a widget for rendering text. You can use ascii strings or unicode strings.
Snippet
# hello world text
l = Label(text='Hello world')
# multiline text
l = Label(text='Multi\nLine')
# size
l = Label(text='Hello world', font_size=20)
Bases: kivy.uix.widget.Widget
Label class, see module documentation for more information.
Indicate if you want to use the bold version of your font.
Note
Depending of your font, the bold attribute may have no impact on your text rendering.
bold is a BooleanProperty, default to False
Text color, in the format (r, g, b, a)
color is a ListProperty, default to [1, 1, 1, 1].
File of the font to use. The path used for the font can be a absolute path, or a relative path that will be search with the resource_find() function.
Warning
Depending of your text provider, the font file can be ignored. But you can mostly use this without trouble.
font_name is a StringProperty, default to ‘fonts/DejaVuSans.ttf’.
Font size of the text. The font size is in pixels.
font_size is a NumericProperty, default to 10.
Horizontal alignment of the text.
halign is a OptionProperty, default to ‘left’. Available options are : left, center and right.
Indicate if you want to use the italic version of your font.
Note
Depending of your font, the italic attribute may have no impact on your text rendering.
italic is a BooleanProperty, default to False
Padding of the text, in the format (padding_x, padding_y)
padding is a ReferenceListProperty of (padding_x, padding_y) properties.
Horizontal padding of the text, inside the widget box.
padding_x is a NumericProperty, default to 0
Vertical padding of the text, inside the widget box.
padding_x is a NumericProperty, default to 0
Text of the label.
Creation of a simple hello world
widget = Label(text='Hello world')
If you want to create the widget with an unicode string, use
widget = Label(text=u'My unicode string')
Texture object of the text. The text is rendered after each properties changes, and stored inside this property. You can use this texture for any graphics elements.
Depending of the texture creation, the value will be a Texture or TextureRegion object.
Warning
The texture update is scheduled for the next frame. That’s mean if you really want the texture just after changing a property, you need to call texture_update() function before
l = Label(text='Hello world')
# l.texture is good
l.font_size = 50
# l.texture is not updated yet
l.update_texture()
# l.texture is good now.
texture is a ObjectProperty, default to None.
Texture size of the text.
Warning
The texture size is set after the texture property. So if you listen on the change to texture, the property texture_size will be not yet updated. Use self.texture.size instead.
Force texture recreation with the current Label properties.
After this function call, the texture and :data`texture_size` will be updated in this order.
Vertical alignment of the text.
valign is a OptionProperty, default to ‘bottom’. Available options are : bottom, middle and top.