简体   繁体   English

Pygtk3指定gtk3标签/ CellRenderer字体

[英]Pygtk3 Specify gtk3 Label/CellRenderer font

According to a pygtk2 doc on faq.pygtk.org The way to change a font is by a definition like so: 根据faq.pygtk.org上的pygtk2文档,更改字体的方法是通过如下定义:

...

label = gtk.Label("MyLabel")
label.modify_font(pango.FontDescription("sans 48"))
...

What is the equivalent in pyGtk3? pyGtk3中的等效项是什么?

I was looking to avoid the use of a gtk css definition. 我一直在寻找避免使用gtk CSS定义的方法。 Though I would happily accept an answer that utilizes gtk's css support. 虽然我很乐意接受利用gtk的css支持的答案。

My target font is gnu unifont ( unifont medium ), in case that changes anything; 我的目标字体是gnu unifont( unifont medium ),以防万一。 This font is readily available in tty format. 该字体易于使用tty格式。

I've assumed at this point that applying a font to a label is similar to applying a font to a table cell, though an example of both would be ideal. 在这一点上,我假设将字体应用于标签类似于将字体应用于表格单元,尽管两者的示例都是理想的。

The latest pygtk3 docs don't appear to cover this topic whatsoever: http://python-gtk-3-tutorial.readthedocs.org/en/latest/label.html , and font is hardly mentioned accross the entirety of the documentation. 最新的pygtk3文档似乎并未涵盖该主题: http ://python-gtk-3-tutorial.readthedocs.org/en/latest/label.html,并且在整个文档中几乎都没有提到字体。

It's basically the same: 基本上是一样的:

from gi.repository import Gtk, Pango
label = Gtk.Label('MyLabel')
label.modify_font(Pango.FontDescription('Dejavu Sans Mono'))

One approach is to use Pango markup [1]: 一种方法是使用Pango标记[1]:

label = Gtk.Label()
label.set_markup("<span font_desc='unifont medium'>%s</span>" % 'some text')

[1] https://developer.gnome.org/pango/stable/PangoMarkupFormat.html [1] https://developer.gnome.org/pango/stable/PangoMarkupFormat.html

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

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