简体   繁体   中英

How can you use a font file in GTK

I'm writing an open source program (key-train) in Python and GTK (with Cairo) and I would like to use some more attractive fonts. I was hoping that it would be possible to load a ttf font from within the program and just use it (instead of installing it), but I haven't been able to figure out how to do this.

您可能想要查看此功能请求如果使用后端的cairo和freetype,它会显示一个工作轮次。

You could use pango to set the ttf font:

#!/usr/bin/env python
import pango
import gtk

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
main_vbox = gtk.VBox(homogeneous=False,spacing=0)
window.add(main_vbox)
textview = gtk.TextView()
main_vbox.pack_start(textview,expand=False,fill=True,padding=0)
textbuffer = textview.get_buffer()
font_desc=pango.FontDescription('FreeSans Bold 64')
textview.modify_font(font_desc)
textbuffer.set_text('Hi Scott Kirkwood')
textview.show()
main_vbox.show()
window.show()
gtk.main()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM