Skip to content

Gtk.Inscription

class — extends Widget, Accessible, AccessibleText, Buildable, ConstraintTarget

Shows text in a predefined area.

You likely want to use GtkLabel instead as this widget is intended only for a small subset of use cases. The main scenario envisaged is inside lists such as GtkColumnView.

While a GtkLabel sizes itself depending on the text that is displayed, GtkInscription is given a size and inscribes the given text into that space as well as it can.

Users of this widget should take care to plan behaviour for the common case where the text doesn't fit exactly in the allocated space.

CSS nodes

GtkInscription has a single CSS node with the name label.

Constructors

new

@classmethod
def new(cls, text: str | None = ...) -> Widget

Creates a new GtkInscription with the given text.

Parameters:

  • text — The text to display.

Methods

get_attributes

def get_attributes(self) -> Pango.AttrList | None

Gets the inscription's attribute list.

get_min_chars

def get_min_chars(self) -> int

Gets the min-chars of the inscription.

See the Inscription.min-chars property.

get_min_lines

def get_min_lines(self) -> int

Gets the min-lines of the inscription.

See the Inscription.min-lines property.

get_nat_chars

def get_nat_chars(self) -> int

Gets the nat-chars of the inscription.

See the Inscription.nat-chars property.

get_nat_lines

def get_nat_lines(self) -> int

Gets the nat-lines of the inscription.

See the Inscription.nat-lines property.

get_text

def get_text(self) -> str | None

Gets the text that is displayed.

get_text_overflow

def get_text_overflow(self) -> InscriptionOverflow

Gets the inscription's overflow method.

get_wrap_mode

def get_wrap_mode(self) -> Pango.WrapMode

Returns line wrap mode used by the inscription.

See Inscription.set_wrap_mode.

get_xalign

def get_xalign(self) -> float

Gets the xalign of the inscription.

See the Inscription.xalign property.

get_yalign

def get_yalign(self) -> float

Gets the yalign of the inscription.

See the Inscription.yalign property.

set_attributes

def set_attributes(self, attrs: Pango.AttrList | None = ...) -> None

Apply attributes to the inscription text.

These attributes will not be evaluated for sizing the inscription.

Parameters:

set_markup

def set_markup(self, markup: str | None = ...) -> None

Utility function to set the text and attributes to be displayed.

See the Inscription.markup property.

Parameters:

  • markup — The markup to display

set_min_chars

def set_min_chars(self, min_chars: int) -> None

Sets the min-chars of the inscription.

See the Inscription.min-chars property.

Parameters:

  • min_chars — the minimum number of characters that should fit, approximately

set_min_lines

def set_min_lines(self, min_lines: int) -> None

Sets the min-lines of the inscription.

See the Inscription.min-lines property.

Parameters:

  • min_lines — the minimum number of lines that should fit, approximately

set_nat_chars

def set_nat_chars(self, nat_chars: int) -> None

Sets the nat-chars of the inscription.

See the Inscription.nat-chars property.

Parameters:

  • nat_chars — the number of characters that should ideally fit, approximately

set_nat_lines

def set_nat_lines(self, nat_lines: int) -> None

Sets the nat-lines of the inscription.

See the Inscription.nat-lines property.

Parameters:

  • nat_lines — the number of lines that should ideally fit

set_text

def set_text(self, text: str | None = ...) -> None

Sets the text to be displayed.

Parameters:

  • text — The text to display

set_text_overflow

def set_text_overflow(self, overflow: InscriptionOverflow | int) -> None

Sets what to do when the text doesn't fit.

Parameters:

  • overflow — the overflow method to use

set_wrap_mode

def set_wrap_mode(self, wrap_mode: Pango.WrapMode | int) -> None

Controls how line wrapping is done.

Parameters:

  • wrap_mode — the line wrapping mode

set_xalign

def set_xalign(self, xalign: float) -> None

Sets the xalign of the inscription.

See the Inscription.xalign property.

Parameters:

  • xalign — the new xalign value, between 0 and 1

set_yalign

def set_yalign(self, yalign: float) -> None

Sets the yalign of the inscription.

See the Inscription.yalign property.

Parameters:

  • yalign — the new yalign value, between 0 and 1

Properties

attributes

attributes: Pango.AttrList  # read/write

A list of style attributes to apply to the text of the inscription.

markup

markup: str  # read/write

Utility property that sets both the Inscription.text and Inscription.attributes properties, mainly intended for use in GtkBuilder ui files to ease translation support and bindings.

This function uses Pango.parse_markup to parse the markup into text and attributes. The markup must be valid. If you cannot ensure that, consider using Pango.parse_markup and setting the two properties yourself.

min_chars

min_chars: int  # read/write

The number of characters that should fit into the inscription at minimum.

This influences the requested width, not the width actually given to the widget, which might turn out to be larger.

Note that this is an approximate character width, so some characters might be wider and some might be thinner, so do not expect the number of characters to exactly match.

If you set this property to 0, the inscription will not request any width at all and its width will be determined entirely by its surroundings.

min_lines

min_lines: int  # read/write

The number of lines that should fit into the inscription at minimum.

This influences the requested height, not the height actually given to the widget, which might turn out to be larger.

Note that this is an approximate line height, so if the text uses things like fancy Unicode or attribute that influence the height, the text might not fit.

If you set this property to 0, the inscription will not request any height at all and its height will be determined entirely by its surroundings.

nat_chars

nat_chars: int  # read/write

The number of characters that should ideally fit into the inscription.

This influences the requested width, not the width actually given to the widget. The widget might turn out larger as well as smaller.

If this property is set to a value smaller than Inscription.min-chars, that value will be used. In particular, for the default value of 0, this will always be the case.

nat_lines

nat_lines: int  # read/write

The number of lines that should ideally fit into the inscription.

This influences the requested height, not the height actually given to the widget. The widget might turn out larger as well as smaller.

If this property is set to a value smaller than Inscription.min-lines, that value will be used. In particular, for the default value of 0, this will always be the case.

text

text: str  # read/write

The displayed text.

text_overflow

text_overflow: InscriptionOverflow | int  # read/write

The overflow method to use for the text.

wrap_mode

wrap_mode: Pango.WrapMode | int  # read/write

Controls how the line wrapping is done.

Note that unlike GtkLabel, the default here is Pango.WrapMode.WORD_CHAR.

xalign

xalign: float  # read/write

The horizontal alignment of the text inside the allocated size.

Compare this to Widget.halign, which determines how the inscription's size allocation is positioned in the available space.

yalign

yalign: float  # read/write

The vertical alignment of the text inside the allocated size.

Compare this to Widget.valign, which determines how the inscription's size allocation is positioned in the available space.