简体   繁体   English

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

[英]How can I change the font size in GTK?

Is there an easy way to change the font size of text elements in GTK? 有没有一种简单的方法来改变GTK中文本元素的字体大小? Right now the best I can do is do set_markup on a label, with something silly like: 现在,我能做的最好的事情是在标签上做set_markup ,有些傻话:

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. 这1)要求我设置字体,2)似乎需要很多开销(必须解析标记),3)会让按钮等字体大小变得烦人。 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): 如果你想在你的应用程序中更改整体字体,我会把这个工作留给gtkrc(然后成为一个谷歌问题,并且“gtkrc字体”查询将我们带到这个ubuntu论坛链接 ,其中包含以下代码片段gtkrc文件):

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. 据我所知,如果你有更精确的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. YMMV适用于不同的平台,但如果使用GTK,AFAIK此文件始终存在于某个位置,并允许用户负责演示详细信息。

In C, you can do: 在C中,您可以:

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

In PyGTK, I believe it's something like: 在PyGTK中,我相信它是这样的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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