如何更改 GTK 中的字体大小?

发布于 2024-08-02 04:06:16 字数 278 浏览 3 评论 0原文

有没有一种简单的方法可以更改 GTK 中文本元素的字体大小? 现在我能做的最好的事情就是在标签上执行 set_markup ,并添加一些愚蠢的内容,例如:

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

这 1) 需要我设置字体,2) 似乎有很多开销(必须解析标记) ), 3) 会让改变按钮的字体大小等变得很烦人。 有没有更好的办法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2024-08-09 04:06:16

如果您想更改应用程序中的整体字体,我会将这项工作留给 gtkrc (然后成为谷歌问题,并且“gtkrc font”查询将我们带到 此 ubuntu 论坛链接,其中包含以下 gtkrc 文件片段):(

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

将字体替换为您/用户需要的字体)

然后用户将获得一致的体验,并且能够轻松更改设置,而无需他们插入代码,也无需处理维护个人配置相关代码的开销。 我知道如果您对 widget_class 有更精确的定义,您可以使此设置更具体。

YMMV 适用于不同的平台,但据我所知,如果使用 GTK,该文件始终存在于某个位置,并允许用户负责演示细节。

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.

相守太难 2024-08-09 04:06:16

在 C 中,你可以这样做:

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

在 PyGTK 中,我相信它是这样的:

pangoFont = pango.FontDescription("Tahoma 5.4")
lbl.modify_font(pangoFont)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文