Skip to content

Gtk.FontDialogButton

class — extends Widget, Accessible, Buildable, ConstraintTarget

Opens a font chooser dialog to select a font.

<picture> <source srcset="font-button-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkFontDialogButton" src="font-button.png"> </picture>

It is suitable widget for selecting a font in a preference dialog.

CSS nodes

fontbutton
╰── button.font
    ╰── [content]

GtkFontDialogButton has a single CSS node with name fontbutton which contains a button node with the .font style class.

Constructors

new

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

Creates a new GtkFontDialogButton with the given GtkFontDialog.

You can pass NULL to this function and set a GtkFontDialog later. The button will be insensitive until that happens.

Parameters:

  • dialog — the GtkFontDialog to use

Methods

get_dialog

def get_dialog(self) -> FontDialog | None

Returns the GtkFontDialog of self.

get_font_desc

def get_font_desc(self) -> Pango.FontDescription | None

Returns the font of the button.

This function is what should be used to obtain the font that was chosen by the user. To get informed about changes, listen to "notify::font-desc".

get_font_features

def get_font_features(self) -> str | None

Returns the font features of the button.

This function is what should be used to obtain the font features that were chosen by the user. To get informed about changes, listen to "notify::font-features".

Note that the button will only let users choose font features if FontDialogButton.level is set to GTK_FONT_LEVEL_FEATURES.

get_language

def get_language(self) -> Pango.Language | None

Returns the language that is used for font features.

get_level

def get_level(self) -> FontLevel

Returns the level of detail at which this dialog lets the user select fonts.

get_use_font

def get_use_font(self) -> bool

Returns whether the selected font is used in the label.

get_use_size

def get_use_size(self) -> bool

Returns whether the selected font size is used in the label.

set_dialog

def set_dialog(self, dialog: FontDialog) -> None

Sets a GtkFontDialog object to use for creating the font chooser dialog that is presented when the user clicks the button.

Parameters:

  • dialog — the new GtkFontDialog

set_font_desc

def set_font_desc(self, font_desc: Pango.FontDescription) -> None

Sets the font of the button.

Parameters:

  • font_desc — the new font

set_font_features

def set_font_features(self, font_features: str | None = ...) -> None

Sets the font features of the button.

Parameters:

  • font_features — the font features

set_language

def set_language(self, language: Pango.Language | None = ...) -> None

Sets the language to use for font features.

Parameters:

  • language — the new language

set_level

def set_level(self, level: FontLevel | int) -> None

Sets the level of detail at which this dialog lets the user select fonts.

Parameters:

  • level — the level of detail

set_use_font

def set_use_font(self, use_font: bool) -> None

If use_font is TRUE, the font name will be written using the selected font.

Parameters:

  • use_font — If TRUE, font name will be written using the chosen font

set_use_size

def set_use_size(self, use_size: bool) -> None

If use_size is TRUE, the font name will be written using the selected font size.

Parameters:

  • use_size — If TRUE, font name will be written using the chosen font size

Properties

dialog

dialog: FontDialog  # read/write

The GtkFontDialog that contains parameters for the font chooser dialog.

font_desc

font_desc: Pango.FontDescription  # read/write

The selected font.

This property can be set to give the button its initial font, and it will be updated to reflect the users choice in the font chooser dialog.

Listen to notify::font-desc to get informed about changes to the buttons font.

font_features

font_features: str  # read/write

The selected font features.

This property will be updated to reflect the users choice in the font chooser dialog.

Listen to notify::font-features to get informed about changes to the buttons font features.

language

language: Pango.Language  # read/write

The selected language for font features.

This property will be updated to reflect the users choice in the font chooser dialog.

Listen to notify::language to get informed about changes to the buttons language.

level

level: FontLevel | int  # read/write

The level of detail for the font chooser dialog.

use_font

use_font: bool  # read/write

Whether the buttons label will be drawn in the selected font.

use_size

use_size: bool  # read/write

Whether the buttons label will use the selected font size.

Signals

activate

def on_activate(self) -> None: ...

Emitted when the font dialog button is activated.

The ::activate signal on GtkFontDialogButton is an action signal and emitting it causes the button to pop up its dialog.