How to use a custom font in a GTK app

拟墨画扇 提交于 2019-12-06 08:22:27

问题


I have a font file /path/to/app/fonts/custom-font.ttf and I want to use it. How do you import a custom TTF for use in a GTK+3.0 app?

from gi.repository import Gtk, Pango

# ...

lbl = Gtk.Label()
lbl.modify_font(Pango.FontDescription("sans 48"))
# lbl.modify_font(Pango.FontDescription("custom-font 48"))

回答1:


If you want to using it as a preview to your own app, install the font and uncomment the last line (provide the right name). If you want to use it as custom font for final release, i suggest you package with the font and make a script to install it. A little note, (in C), ".modify_font" deprecated since Gtk 3.0, use .override_font instead.



来源:https://stackoverflow.com/questions/16598777/how-to-use-a-custom-font-in-a-gtk-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!