HOWTO: Set Main Application Font in PyGTK

Google Mike googlemike at hotpop.com
Wed Sep 1 21:31:17 EDT 2004


This was a tough one (at least for me), and wasn't exactly what I
wanted when I was working on just setting on item's font, but shows
how you can change the font for an entire PyGTK application. I
stumbled on to it by accident.

Once you have your widget as, say, variable 'w', do this:

w.get_settings().set_string_property('gtk-font-name', 'sans normal
9','');
# some other font choices are:
# courier bold 10
# serif oblique 12
# you get the idea?

...I know, I know, it doesn't make sense to me either, but once you
attempt this on any widget in your project, the whole project changes
its fonts. At least it does with my project. Note I did my project in
Glade as one big Glade XML file, then loaded it in with PyGTK. I have
RH9 Linux and I'm using the defaults with that, which I think is
PyGTK2, Python 2.2, and Glade 2.

Anyway, I hope this helps you. Now if anyone knows how to change the
font and size on a single radio button in PyGTK, I welcome the
suggestion. I don't think it can be done.



More information about the Python-list mailing list