2

According to a pygtk2 doc on faq.pygtk.org The way to change a font is by a definition like so:

...

label = gtk.Label("MyLabel")
label.modify_font(pango.FontDescription("sans 48"))
...

What is the equivalent in pyGtk3?

I was looking to avoid the use of a gtk css definition. Though I would happily accept an answer that utilizes gtk's css support.

My target font is gnu unifont (unifont medium), in case that changes anything; This font is readily available in tty format.

I've assumed at this point that applying a font to a label is similar to applying a font to a table cell, though an example of both would be ideal.

The latest pygtk3 docs don't appear to cover this topic whatsoever: http://python-gtk-3-tutorial.readthedocs.org/en/latest/label.html, and font is hardly mentioned accross the entirety of the documentation.

Simon Feltman
  • 1,120
  • 7
  • 8
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147

2 Answers2

5

It's basically the same:

from gi.repository import Gtk, Pango
label = Gtk.Label('MyLabel')
label.modify_font(Pango.FontDescription('Dejavu Sans Mono'))
Havok
  • 5,776
  • 1
  • 35
  • 44
3

One approach is to use Pango markup [1]:

label = Gtk.Label()
label.set_markup("<span font_desc='unifont medium'>%s</span>" % 'some text')

[1] https://developer.gnome.org/pango/stable/PangoMarkupFormat.html

Simon Feltman
  • 1,120
  • 7
  • 8