如何更改GTK中的字体大小? [英] How can I change the font size in GTK?

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

问题描述

有没有一种简单的方法来改变GTK文本元素的字体大小?现在我能做的最好的事情就是在标签上做 set_markup ,其中有些东西很傻:

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

这1)要求我设置字体,2)看起来像很多的开销(不得不解析标记),3)会令人讨厌改变字体大小按钮等。有没有更好的方法?如果你想改变你的应用程序的总体字体,我会离开这个工作到gtkrc(然后成为一个谷歌的问题,gtkrc字体查询带给我们这个Ubuntu论坛链接,其中包含以下gtkrc文件片段:

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

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

然后用户将获得一致的体验,并且能够轻松地更改设置,而无需在代码中进行篡改,也无需处理维护个人配置相关代码的开销。我知道你可以使这个设置更具体,如果你有一个更精确的widget_class定义。



YMMV为不同的平台,但AFAIK这个文件总是存在于某个位置如果GTK正在使用,并允许用户负责演示的细节。

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?

解决方案

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.

这篇关于如何更改GTK中的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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