FontButton

The FontButton provides access to a FontChooserDialog. The button is used when space is limited to allow selecting of a font.

Constructor

The FontButton can be constructed using the following:

fontbutton = Gtk.FontButton(title, font)

When the title parameter has been specified, the text string is displayed on the dialog which appears when the FontButton has been clicked. Also, a font value can be declared to allow a font, style and size option at construction time.

Methods

The title of the dialog which is displayed can be set with:

fontbutton.set_title(title)

Signals

The commonly used signals of an FontButton are:

"font-set" (fontbutton)

A "font-set" signal emits from the FontButton when a font has been selected and the OK button has been pressed on the dialog.

If only certain elements of the font selected are required use the following methods:

font_face = fontbutton.get_font_face()
font_size = fontbutton.get_font_size()
font_desc = fontbutton.get_font_desc()

Example

Below is an example of a FontButton:

#!/usr/bin/env python3

from gi.repository import Gtk

def font_changed(fontbutton):
    print("Font selected: %s" % fontbutton.get_font_name())

window = Gtk.Window()
window.set_default_size(150, -1)
window.connect("destroy", Gtk.main_quit)

fontbutton = Gtk.FontButton(title="FontButton")
fontbutton.connect("font-set", font_changed)
window.add(fontbutton)

window.show_all()

Gtk.main()

Download: FontButton