如何更改 GTK 中的字体大小?
有没有一种简单的方法可以更改 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想更改应用程序中的整体字体,我会将这项工作留给 gtkrc (然后成为谷歌问题,并且“gtkrc font”查询将我们带到 此 ubuntu 论坛链接,其中包含以下 gtkrc 文件片段):(
将字体替换为您/用户需要的字体)
然后用户将获得一致的体验,并且能够轻松更改设置,而无需他们插入代码,也无需处理维护个人配置相关代码的开销。 我知道如果您对 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):
(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.
在 C 中,你可以这样做:
在 PyGTK 中,我相信它是这样的:
In C, you can do:
In PyGTK, I believe it's something like: