I have a fontbutton using pygtk. Initially, i do not want to set the font, as the system will take its default one. My question is what is the line of code to get the default font used by the system , so that i keep things default at first. Later after user changes the font, their respective fonts should apply. Can anyone help?
How to get the default font used by the system using pygtk or pango?
3.9k views Asked by mrabhiram At
4
There are 4 answers
0
On
If you are on GNOME, then you can get the default font like this. (Caution: untested)
from gi.repository import Gio
settings = Gio.Settings('org.gnome.desktop.interface')
font_name = settings.get_string('font-name')
You can also use the keys monospace-font-name
and document-font-name
as appropriate (I forget the name of the key for the window title font.)
Gtk is a toolkit that can run on many operating systems and desktop environments. Gtk is not responsible for the default fonts and colors. Therefore there is (as far as I know) no single function to get these values from Gtk.
There is probably not one default font in your OS/DE, but many. On Ubuntu for example, you can choose those in the (advanced) system settings:
If you need to know the default font of a specific widget, e.g. a Label, you can do the following: