如何在GTK应用程序中使用自定义字体 [英] How to use a custom font in a GTK app

查看:220
本文介绍了如何在GTK应用程序中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字体文件 /path/to/app/fonts/custom-font.ttf ,我想使用它。如何导入自定义TTF以用于GTK + 3.0应用程序?

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"))


推荐答案

如果您想将其用作您自己的应用的预览,请安装字体并取消注释最后一行(提供正确的名称)。如果你想用它作为最终版本的自定义字体,我建议你用字体打包并制作一个脚本来安装它。
从Ck开始,.modify_font自Gtk 3.0开始弃用,请使用.override_font。

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.

这篇关于如何在GTK应用程序中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆