PyGTK and fonts

Gary Herron gherron at islandtraining.com
Tue Sep 9 04:02:41 EDT 2003


On Monday 08 September 2003 08:34 pm, Tad Marko wrote:
> Howdy!
>
> I'm pretty new to both Python and PyGTK (about 10 hours at this
> point), so please forgive me if this question has already been
> answered somewhere. Basically, I've got a small program with a
> GtkTextView and I'd like to change the font to a monospaced font.
> Preferably the default monspace font for Gnome 2. Can anyone show me
> the steps necessary to programatically change the font on the text
> view?
>
> Thanks for any help!
>
> Tad

I too have about 10 hours experience with PyGTK and GTK+ (but about 10
*years* experience with python).  I just figured out the answer to
your question yesterday.  Here it is with the font name coming from
the return value of a font selection dialog.

    fontName = fontDialog.get_font_name()
    pangoFont = pango.FontDescription(fontName)
    textView.modify_font(pangoFont)

The fontName could be hardcoded rather than comming from a font
selection dialog if you wanted.  Here are some examples, the last two
of which are mono-space fonts:

    Sans 12
    Sans Italic 12
    Sans Bold 12
    Sans Bold Italic 12
    Courier 12
    Luxi Mono 12

Gary Herron








More information about the Python-list mailing list