:right-sidebar: True
Label
===================================================================
.. currentmodule:: gi.repository.Gtk
.. class:: Label(**properties: ~typing.Any)
:no-contents-entry:
Superclasses: :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object`
Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.AccessibleText`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`
The ``GtkLabel`` widget displays a small amount of text.
As the name implies, most labels are used to label another widget
such as a :obj:`~gi.repository.Gtk.Button`\.
.. image:: https://docs.gtk.org/gtk4/label.png
Shortcuts and Gestures
--------------------------------------------------------------------------------
``GtkLabel`` supports the following keyboard shortcuts, when the cursor is
visible:
- :kbd:`Shift`\+:kbd:`F10` or :kbd:`Menu` opens the context menu.
- :kbd:`Ctrl`\+:kbd:`A` or :kbd:`Ctrl`\+wzxhzdk:0
selects all.
- :kbd:`Ctrl`\+:kbd:`Shift`\+:kbd:`A` or
:kbd:`Ctrl`\+wzxhzdk:1 unselects all.
Additionally, the following signals have default keybindings:
- :obj:`~gi.repository.Gtk.Label.signals.activate_current_link`
- :obj:`~gi.repository.Gtk.Label.signals.copy_clipboard`
- :obj:`~gi.repository.Gtk.Label.signals.move_cursor`
Actions
--------------------------------------------------------------------------------
``GtkLabel`` defines a set of built-in actions:
- ``clipboard.copy`` copies the text to the clipboard.
- ``clipboard.cut`` doesn't do anything, since text in labels can't be deleted.
- ``clipboard.paste`` doesn't do anything, since text in labels can't be
edited.
- ``link.open`` opens the link, when activated on a link inside the label.
- ``link.copy`` copies the link to the clipboard, when activated on a link
inside the label.
- ``menu.popup`` opens the context menu.
- ``selection.delete`` doesn't do anything, since text in labels can't be
deleted.
- ``selection.select-all`` selects all of the text, if the label allows
selection.
CSS nodes
--------------------------------------------------------------------------------
.. code-block::
:dedent:
label
├── [selection]
├── [link]
┊
╰── [link]
``GtkLabel`` has a single CSS node with the name label. A wide variety
of style classes may be applied to labels, such as .title, .subtitle,
.dim-label, etc. In the ``GtkShortcutsWindow``\, labels are used with the
.keycap style class.
If the label has a selection, it gets a subnode with name selection.
If the label has links, there is one subnode per link. These subnodes
carry the link or visited state depending on whether they have been
visited. In this case, label node also gets a .link style class.
GtkLabel as GtkBuildable
--------------------------------------------------------------------------------
The GtkLabel implementation of the GtkBuildable interface supports a
custom ```` element, which supports any number of ````
elements. The ```` element has attributes named “name“, “value“,
“start“ and “end“ and allows you to specify :obj:`~gi.repository.Pango.Attribute`
values for this label.
An example of a UI definition fragment specifying Pango attributes:
.. code-block:: xml
:dedent:
The start and end attributes specify the range of characters to which the
Pango attribute applies. If start and end are not specified, the attribute is
applied to the whole text. Note that specifying ranges does not make much
sense with translatable attributes. Use markup embedded in the translatable
content instead.
Accessibility
--------------------------------------------------------------------------------
``GtkLabel`` uses the :const:`~gi.repository.Gtk.AccessibleRole.LABEL` role.
Mnemonics
--------------------------------------------------------------------------------
Labels may contain “mnemonics”. Mnemonics are underlined characters in the
label, used for keyboard navigation. Mnemonics are created by providing a
string with an underscore before the mnemonic character, such as ``"_File"``\,
to the functions :obj:`~gi.repository.Gtk.Label.new_with_mnemonic` or
:obj:`~gi.repository.Gtk.Label.set_text_with_mnemonic`\.
Mnemonics automatically activate any activatable widget the label is
inside, such as a :obj:`~gi.repository.Gtk.Button`\; if the label is not inside the
mnemonic’s target widget, you have to tell the label about the target
using :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\.
Here’s a simple example where the label is inside a button:
.. code-block:: c
:dedent:
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new ();
GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
gtk_button_set_child (GTK_BUTTON (button), label);
There’s a convenience function to create buttons with a mnemonic label
already inside:
.. code-block:: c
:dedent:
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
To create a mnemonic for a widget alongside the label, such as a
:obj:`~gi.repository.Gtk.Entry`\, you have to point the label at the entry with
:obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\:
.. code-block:: c
:dedent:
// Pressing Alt+H will focus the entry
GtkWidget *entry = gtk_entry_new ();
GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
Markup (styled text)
--------------------------------------------------------------------------------
To make it easy to format text in a label (changing colors,
fonts, etc.), label text can be provided in a simple
markup format:
Here’s how to create a label with a small font:
.. code-block:: c
:dedent:
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "Small text");
(See the Pango manual for complete documentation] of available
tags, :obj:`~gi.repository.Pango.parse_markup`\)
The markup passed to :obj:`~gi.repository.Gtk.Label.set_markup` must be valid; for example,
literal ``<``\, ``>`` and ``&`` characters must be escaped as ``<``\, ``>``\, and ``&``\.
If you pass text obtained from the user, file, or a network to
:obj:`~gi.repository.Gtk.Label.set_markup`\, you’ll want to escape it with
:obj:`~gi.repository.GLib.markup_escape_text` or :obj:`~gi.repository.GLib.markup_printf_escaped`\.
Markup strings are just a convenient way to set the :obj:`~gi.repository.Pango.AttrList`
on a label; :obj:`~gi.repository.Gtk.Label.set_attributes` may be a simpler way to set
attributes in some cases. Be careful though; :obj:`~gi.repository.Pango.AttrList` tends
to cause internationalization problems, unless you’re applying attributes
to the entire string (i.e. unless you set the range of each attribute
to [0, %G_MAXINT)). The reason is that specifying the start_index and
end_index for a :obj:`~gi.repository.Pango.Attribute` requires knowledge of the exact
string being displayed, so translations will cause problems.
Selectable labels
--------------------------------------------------------------------------------
Labels can be made selectable with :obj:`~gi.repository.Gtk.Label.set_selectable`\.
Selectable labels allow the user to copy the label contents to
the clipboard. Only labels that contain useful-to-copy information—such
as error messages—should be made selectable.
Text layout
--------------------------------------------------------------------------------
A label can contain any number of paragraphs, but will have
performance problems if it contains more than a small number.
Paragraphs are separated by newlines or other paragraph separators
understood by Pango.
Labels can automatically wrap text if you call :obj:`~gi.repository.Gtk.Label.set_wrap`\.
:obj:`~gi.repository.Gtk.Label.set_justify` sets how the lines in a label align
with one another. If you want to set how the label as a whole aligns
in its available space, see the :obj:`~gi.repository.Gtk.Widget.props.halign` and
:obj:`~gi.repository.Gtk.Widget.props.valign` properties.
The :obj:`~gi.repository.Gtk.Label.props.width_chars` and :obj:`~gi.repository.Gtk.Label.props.max_width_chars`
properties can be used to control the size allocation of ellipsized or
wrapped labels. For ellipsizing labels, if either is specified (and less
than the actual text size), it is used as the minimum width, and the actual
text size is used as the natural width of the label. For wrapping labels,
width-chars is used as the minimum width, if specified, and max-width-chars
is used as the natural width. Even if max-width-chars specified, wrapping
labels will be rewrapped to use all of the available width.
Links
--------------------------------------------------------------------------------
GTK supports markup for clickable hyperlinks in addition to regular Pango
markup. The markup for links is borrowed from HTML, using the ```` with
“href“, “title“ and “class“ attributes. GTK renders links similar to the
way they appear in web browsers, with colored, underlined text. The “title“
attribute is displayed as a tooltip on the link. The “class“ attribute is
used as style class on the CSS node for the link.
An example of inline links looks like this:
.. code-block:: c
:dedent:
const char *text =
"Go to the "
""
"GTK website for more...";
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), text);
It is possible to implement custom handling for links and their tooltips
with the :obj:`~gi.repository.Gtk.Label.signals.activate_link` signal and the
:obj:`~gi.repository.Gtk.Label.get_current_uri` function.
Constructors
------------
.. rst-class:: interim-class
.. class:: Label
:no-index:
.. classmethod:: new(str: str | None = None) -> ~gi.repository.Gtk.Widget
Creates a new label with the given text inside it.
You can pass :const:`None` to get an empty label widget.
:param str: The text of the label
.. classmethod:: new_with_mnemonic(str: str | None = None) -> ~gi.repository.Gtk.Widget
Creates a new ``GtkLabel``\, containing the text in ``str``\.
If characters in ``str`` are preceded by an underscore, they are
underlined. If you need a literal underscore character in a label, use
'__' (two underscores). The first underlined character represents a
keyboard accelerator called a mnemonic. The mnemonic key can be used
to activate another widget, chosen automatically, or explicitly using
:obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\.
If :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget` is not called, then the first
activatable ancestor of the ``GtkLabel`` will be chosen as the mnemonic
widget. For instance, if the label is inside a button or menu item,
the button or menu item will automatically become the mnemonic widget
and be activated by the mnemonic.
:param str: The text of the label, with an underscore in front of the
mnemonic character
Methods
-------
.. rst-class:: interim-class
.. class:: Label
:no-index:
.. method:: get_attributes() -> ~gi.repository.Pango.AttrList | None
Gets the label's attribute list.
This is the :obj:`~gi.repository.Pango.AttrList` that was set on the label using
:obj:`~gi.repository.Gtk.Label.set_attributes`\, if any. This function does not
reflect attributes that come from the label's markup (see
:obj:`~gi.repository.Gtk.Label.set_markup`\). If you want to get the effective
attributes for the label, use
``pango_layout_get_attributes (gtk_label_get_layout (self))``\.
.. method:: get_current_uri() -> str | None
Returns the URI for the currently active link in the label.
The active link is the one under the mouse pointer or, in a
selectable label, the link in which the text cursor is currently
positioned.
This function is intended for use in a :obj:`~gi.repository.Gtk.Label.signals.activate_link`
handler or for use in a :obj:`~gi.repository.Gtk.Widget.signals.query_tooltip` handler.
.. method:: get_ellipsize() -> ~gi.repository.Pango.EllipsizeMode
Returns the ellipsizing position of the label.
See :obj:`~gi.repository.Gtk.Label.set_ellipsize`\.
.. method:: get_extra_menu() -> ~gi.repository.Gio.MenuModel | None
Gets the extra menu model of ``label``\.
See :obj:`~gi.repository.Gtk.Label.set_extra_menu`\.
.. method:: get_justify() -> ~gi.repository.Gtk.Justification
Returns the justification of the label.
See :obj:`~gi.repository.Gtk.Label.set_justify`\.
.. method:: get_label() -> str
Fetches the text from a label.
The returned text includes any embedded underlines indicating
mnemonics and Pango markup. (See :obj:`~gi.repository.Gtk.Label.get_text`\).
.. method:: get_layout() -> ~gi.repository.Pango.Layout
Gets the ``PangoLayout`` used to display the label.
The layout is useful to e.g. convert text positions to pixel
positions, in combination with :obj:`~gi.repository.Gtk.Label.get_layout_offsets`\.
The returned layout is owned by the ``label`` so need not be
freed by the caller. The ``label`` is free to recreate its layout
at any time, so it should be considered read-only.
.. method:: get_layout_offsets() -> tuple[int, int]
Obtains the coordinates where the label will draw its ``PangoLayout``\.
The coordinates are useful to convert mouse events into coordinates
inside the :obj:`~gi.repository.Pango.Layout`\, e.g. to take some action if some part
of the label is clicked. Remember when using the :obj:`~gi.repository.Pango.Layout`
functions you need to convert to and from pixels using :func:`~gi.repository.Pango.PIXELS`
or :obj:`~gi.repository.Pango.SCALE`\.
.. method:: get_lines() -> int
Gets the number of lines to which an ellipsized, wrapping
label should be limited.
See :obj:`~gi.repository.Gtk.Label.set_lines`\.
.. method:: get_max_width_chars() -> int
Retrieves the desired maximum width of ``label``\, in characters.
See :obj:`~gi.repository.Gtk.Label.set_width_chars`\.
.. method:: get_mnemonic_keyval() -> int
Return the mnemonic accelerator.
If the label has been set so that it has a mnemonic key this function
returns the keyval used for the mnemonic accelerator. If there is no
mnemonic set up it returns ``GDK_KEY_VoidSymbol``\.
.. method:: get_mnemonic_widget() -> ~gi.repository.Gtk.Widget | None
Retrieves the target of the mnemonic (keyboard shortcut) of this
label.
See :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\.
.. method:: get_natural_wrap_mode() -> ~gi.repository.Gtk.NaturalWrapMode
Returns line wrap mode used by the label.
See :obj:`~gi.repository.Gtk.Label.set_natural_wrap_mode`\.
.. versionadded:: 4.6
.. method:: get_selectable() -> bool
Returns whether the label is selectable.
.. method:: get_selection_bounds() -> tuple[bool, int, int]
Gets the selected range of characters in the label.
.. method:: get_single_line_mode() -> bool
Returns whether the label is in single line mode.
.. method:: get_tabs() -> ~gi.repository.Pango.TabArray | None
Gets the tabs for ``self``\.
The returned array will be :const:`None` if “standard” (8-space) tabs are used.
Free the return value with :obj:`~gi.repository.Pango.TabArray.free`\.
.. versionadded:: 4.8
.. method:: get_text() -> str
Fetches the text from a label.
The returned text is as it appears on screen. This does not include
any embedded underlines indicating mnemonics or Pango markup. (See
:obj:`~gi.repository.Gtk.Label.get_label`\)
.. method:: get_use_markup() -> bool
Returns whether the label’s text is interpreted as Pango markup.
See :obj:`~gi.repository.Gtk.Label.set_use_markup`\.
.. method:: get_use_underline() -> bool
Returns whether an embedded underlines in the label indicate mnemonics.
See :obj:`~gi.repository.Gtk.Label.set_use_underline`\.
.. method:: get_width_chars() -> int
Retrieves the desired width of ``label``\, in characters.
See :obj:`~gi.repository.Gtk.Label.set_width_chars`\.
.. method:: get_wrap() -> bool
Returns whether lines in the label are automatically wrapped.
See :obj:`~gi.repository.Gtk.Label.set_wrap`\.
.. method:: get_wrap_mode() -> ~gi.repository.Pango.WrapMode
Returns line wrap mode used by the label.
See :obj:`~gi.repository.Gtk.Label.set_wrap_mode`\.
.. method:: get_xalign() -> float
Gets the ``xalign`` of the label.
See the :obj:`~gi.repository.Gtk.Label.props.xalign` property.
.. method:: get_yalign() -> float
Gets the ``yalign`` of the label.
See the :obj:`~gi.repository.Gtk.Label.props.yalign` property.
.. method:: select_region(start_offset: int, end_offset: int) -> None
Selects a range of characters in the label, if the label is selectable.
See :obj:`~gi.repository.Gtk.Label.set_selectable`\. If the label is not selectable,
this function has no effect. If ``start_offset`` or
``end_offset`` are -1, then the end of the label will be substituted.
:param start_offset: start offset (in characters not bytes)
:param end_offset: end offset (in characters not bytes)
.. method:: set_attributes(attrs: ~gi.repository.Pango.AttrList | None = None) -> None
Apply attributes to the label text.
The attributes set with this function will be applied and merged with
any other attributes previously effected by way of the
:obj:`~gi.repository.Gtk.Label.props.use_underline` or :obj:`~gi.repository.Gtk.Label.props.use_markup`
properties. While it is not recommended to mix markup strings with
manually set attributes, if you must; know that the attributes will
be applied to the label after the markup string is parsed.
:param attrs: a :obj:`~gi.repository.Pango.AttrList`
.. method:: set_ellipsize(mode: ~gi.repository.Pango.EllipsizeMode) -> None
Sets the mode used to ellipsize the text.
The text will be ellipsized if there is not enough space
to render the entire string.
:param mode: a ``PangoEllipsizeMode``
.. method:: set_extra_menu(model: ~gi.repository.Gio.MenuModel | None = None) -> None
Sets a menu model to add when constructing
the context menu for ``label``\.
:param model: a ``GMenuModel``
.. method:: set_justify(jtype: ~gi.repository.Gtk.Justification) -> None
Sets the alignment of the lines in the text of the label relative to
each other.
:const:`~gi.repository.Gtk.Justification.LEFT` is the default value when the widget is first created
with :obj:`~gi.repository.Gtk.Label.new`\. If you instead want to set the alignment of
the label as a whole, use :obj:`~gi.repository.Gtk.Widget.set_halign` instead.
:obj:`~gi.repository.Gtk.Label.set_justify` has no effect on labels containing
only a single line.
:param jtype: a ``GtkJustification``
.. method:: set_label(str: str) -> None
Sets the text of the label.
The label is interpreted as including embedded underlines and/or Pango
markup depending on the values of the :obj:`~gi.repository.Gtk.Label.props.use_underline`
and :obj:`~gi.repository.Gtk.Label.props.use_markup` properties.
:param str: the new text to set for the label
.. method:: set_lines(lines: int) -> None
Sets the number of lines to which an ellipsized, wrapping label
should be limited.
This has no effect if the label is not wrapping or ellipsized.
Set this to -1 if you don’t want to limit the number of lines.
:param lines: the desired number of lines, or -1
.. method:: set_markup(str: str) -> None
Sets the labels text and attributes from markup.
The string must be marked up with Pango markup
(see :obj:`~gi.repository.Pango.parse_markup`\).
If the ``str`` is external data, you may need to escape it
with :func:`~gi.repository.GLib.markup_escape_text` or :func:`~gi.repository.GLib.markup_printf_escaped`:
.. code-block:: c
:dedent:
GtkWidget *self = gtk_label_new (NULL);
const char *str = "...";
const char *format = "\%s";
char *markup;
markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (self), markup);
g_free (markup);
This function will set the :obj:`~gi.repository.Gtk.Label.props.use_markup` property
to :const:`True` as a side effect.
If you set the label contents using the :obj:`~gi.repository.Gtk.Label.props.label`
property you should also ensure that you set the
:obj:`~gi.repository.Gtk.Label.props.use_markup` property accordingly.
See also: :obj:`~gi.repository.Gtk.Label.set_text`
:param str: a markup string
.. method:: set_markup_with_mnemonic(str: str) -> None
Sets the labels text, attributes and mnemonic from markup.
Parses ``str`` which is marked up with Pango markup (see :obj:`~gi.repository.Pango.parse_markup`\),
setting the label’s text and attribute list based on the parse results.
If characters in ``str`` are preceded by an underscore, they are underlined
indicating that they represent a keyboard accelerator called a mnemonic.
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\.
:param str: a markup string
.. method:: set_max_width_chars(n_chars: int) -> None
Sets the desired maximum width in characters of ``label`` to ``n_chars``\.
:param n_chars: the new desired maximum width, in characters.
.. method:: set_mnemonic_widget(widget: ~gi.repository.Gtk.Widget | None = None) -> None
Associate the label with its mnemonic target.
If the label has been set so that it has a mnemonic key (using
i.e. :obj:`~gi.repository.Gtk.Label.set_markup_with_mnemonic`\,
:obj:`~gi.repository.Gtk.Label.set_text_with_mnemonic`\,
:obj:`~gi.repository.Gtk.Label.new_with_mnemonic`
or the :obj:`~gi.repository.Gtk.Label.props.use_underline` property) the label can be
associated with a widget that is the target of the mnemonic. When the
label is inside a widget (like a :obj:`~gi.repository.Gtk.Button` or a
:obj:`~gi.repository.Gtk.Notebook` tab) it is automatically associated with the correct
widget, but sometimes (i.e. when the target is a :obj:`~gi.repository.Gtk.Entry` next to
the label) you need to set it explicitly using this function.
The target widget will be accelerated by emitting the
:obj:`~gi.repository.Gtk.Widget.signals.mnemonic_activate` signal on it. The default handler for
this signal will activate the widget if there are no mnemonic collisions
and toggle focus between the colliding widgets otherwise.
:param widget: the target ``GtkWidget``\, or :const:`None` to unset
.. method:: set_natural_wrap_mode(wrap_mode: ~gi.repository.Gtk.NaturalWrapMode) -> None
Select the line wrapping for the natural size request.
This only affects the natural size requested, for the actual wrapping used,
see the :obj:`~gi.repository.Gtk.Label.props.wrap_mode` property.
.. versionadded:: 4.6
:param wrap_mode: the line wrapping mode
.. method:: set_selectable(setting: bool) -> None
Makes text in the label selectable.
Selectable labels allow the user to select text from the label,
for copy-and-paste.
:param setting: :const:`True` to allow selecting text in the label
.. method:: set_single_line_mode(single_line_mode: bool) -> None
Sets whether the label is in single line mode.
:param single_line_mode: :const:`True` if the label should be in single line mode
.. method:: set_tabs(tabs: ~gi.repository.Pango.TabArray | None = None) -> None
Sets the default tab stops for paragraphs in ``self``\.
.. versionadded:: 4.8
:param tabs: tabs as a ``PangoTabArray``
.. method:: set_text(str: str) -> None
Sets the text within the ``GtkLabel`` widget.
It overwrites any text that was there before.
This function will clear any previously set mnemonic accelerators,
and set the :obj:`~gi.repository.Gtk.Label.props.use_underline` property to :const:`False` as
a side effect.
This function will set the :obj:`~gi.repository.Gtk.Label.props.use_markup` property
to :const:`False` as a side effect.
See also: :obj:`~gi.repository.Gtk.Label.set_markup`
:param str: The text you want to set
.. method:: set_text_with_mnemonic(str: str) -> None
Sets the label’s text from the string ``str``\.
If characters in ``str`` are preceded by an underscore, they are underlined
indicating that they represent a keyboard accelerator called a mnemonic.
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using :obj:`~gi.repository.Gtk.Label.set_mnemonic_widget`\.
:param str: a string
.. method:: set_use_markup(setting: bool) -> None
Sets whether the text of the label contains markup.
See :obj:`~gi.repository.Gtk.Label.set_markup`\.
:param setting: :const:`True` if the label’s text should be parsed for markup.
.. method:: set_use_underline(setting: bool) -> None
Sets whether underlines in the text indicate mnemonics.
:param setting: :const:`True` if underlines in the text indicate mnemonics
.. method:: set_width_chars(n_chars: int) -> None
Sets the desired width in characters of ``label`` to ``n_chars``\.
:param n_chars: the new desired width, in characters.
.. method:: set_wrap(wrap: bool) -> None
Toggles line wrapping within the ``GtkLabel`` widget.
:const:`True` makes it break lines if text exceeds the widget’s size.
:const:`False` lets the text get cut off by the edge of the widget if
it exceeds the widget size.
Note that setting line wrapping to :const:`True` does not make the label
wrap at its parent container’s width, because GTK widgets
conceptually can’t make their requisition depend on the parent
container’s size. For a label that wraps at a specific position,
set the label’s width using :obj:`~gi.repository.Gtk.Widget.set_size_request`\.
:param wrap: the setting
.. method:: set_wrap_mode(wrap_mode: ~gi.repository.Pango.WrapMode) -> None
Controls how line wrapping is done.
This only affects the label if line wrapping is on. (See
:obj:`~gi.repository.Gtk.Label.set_wrap`\) The default is %PANGO_WRAP_WORD
which means wrap on word boundaries.
For sizing behavior, also consider the :obj:`~gi.repository.Gtk.Label.props.natural_wrap_mode`
property.
:param wrap_mode: the line wrapping mode
.. method:: set_xalign(xalign: float) -> None
Sets the ``xalign`` of the label.
See the :obj:`~gi.repository.Gtk.Label.props.xalign` property.
:param xalign: the new xalign value, between 0 and 1
.. method:: set_yalign(yalign: float) -> None
Sets the ``yalign`` of the label.
See the :obj:`~gi.repository.Gtk.Label.props.yalign` property.
:param yalign: the new yalign value, between 0 and 1
Properties
----------
.. rst-class:: interim-class
.. class:: Label
:no-index:
.. attribute:: props.attributes
:type: ~gi.repository.Pango.AttrList
The type of the None singleton.
.. attribute:: props.ellipsize
:type: ~gi.repository.Pango.EllipsizeMode
The type of the None singleton.
.. attribute:: props.extra_menu
:type: ~gi.repository.Gio.MenuModel
The type of the None singleton.
.. attribute:: props.justify
:type: ~gi.repository.Gtk.Justification
The type of the None singleton.
.. attribute:: props.label
:type: str
The type of the None singleton.
.. attribute:: props.lines
:type: int
The type of the None singleton.
.. attribute:: props.max_width_chars
:type: int
The type of the None singleton.
.. attribute:: props.mnemonic_keyval
:type: int
The type of the None singleton.
.. attribute:: props.mnemonic_widget
:type: ~gi.repository.Gtk.Widget
The type of the None singleton.
.. attribute:: props.natural_wrap_mode
:type: ~gi.repository.Gtk.NaturalWrapMode
The type of the None singleton.
.. versionadded:: 4.6
.. attribute:: props.selectable
:type: bool
The type of the None singleton.
.. attribute:: props.single_line_mode
:type: bool
The type of the None singleton.
.. attribute:: props.tabs
:type: ~gi.repository.Pango.TabArray
The type of the None singleton.
.. versionadded:: 4.8
.. attribute:: props.use_markup
:type: bool
The type of the None singleton.
.. attribute:: props.use_underline
:type: bool
The type of the None singleton.
.. attribute:: props.width_chars
:type: int
The type of the None singleton.
.. attribute:: props.wrap
:type: bool
The type of the None singleton.
.. attribute:: props.wrap_mode
:type: ~gi.repository.Pango.WrapMode
The type of the None singleton.
.. attribute:: props.xalign
:type: float
The type of the None singleton.
.. attribute:: props.yalign
:type: float
The type of the None singleton.
Signals
-------
.. rst-class:: interim-class
.. class:: Label.signals
:no-index:
.. method:: activate_current_link() -> None
The type of the None singleton.
.. method:: activate_link(uri: str) -> bool
The type of the None singleton.
:param uri: the URI that is activated
.. method:: copy_clipboard() -> None
The type of the None singleton.
.. method:: move_cursor(step: ~gi.repository.Gtk.MovementStep, count: int, extend_selection: bool) -> None
The type of the None singleton.
:param step: the granularity of the move, as a ``GtkMovementStep``
:param count: the number of ``step`` units to move
:param extend_selection: :const:`True` if the move should extend the selection