views:

900

answers:

2

Is there an easy way to change the font size of text elements in GTK? Right now the best I can do is do set_markup on a label, with something silly like:

lbl.set_markup("<span font_desc='Tahoma 5.4'>%s</span>" % text)

This 1) requires me to set the font , 2) seems like a lot of overhead (having to parse the markup), and 3) would make it annoying to change the font size of buttons and such. Is there a better way?

+1  A: 

In C, you can do:

gtk_widget_modify_font(lbl, pango_font_description_from_string("Tahoma 5.4"));

In PyGTK, I believe it's something like:

pangoFont = pango.FontDescription("Tahoma 5.4")
lbl.modify_font(pangoFont)
Reed Copsey
+1  A: 

If you want to change font overall in your app(s), I'd leave this job to gtkrc (then becomes a google question, and "gtkrc font" query brings us to this ubuntu forums link which has the following snippet of the the gtkrc file):

style "font"
{
font_name = "Corbel 8"
}
widget_class "*" style "font"
gtk-font-name = "Corbel 8"

(replace the font with the one you/user need)

Then the user will get consistent experience and will be able to change the settings easily without need for them to poke in the code and without you needing to handle the overhead of maintaining your personal configuration-related code. I understand you can make this setting more specific if you have a more precise definition for the widget_class.

YMMV for different platforms, but AFAIK this file is always present at some location if GTK is being used, and allows to the user to be in charge of presentation details.

Andrew Y
is it possible to use a custom gtkrc file for just my application? if so, how can i do that?
Claudiu
try the idea from here: http://www.daa.com.au/pipermail/pygtk/2008-December/016359.html
Andrew Y