Python 带有pygobject的pango属性

Python 带有pygobject的pango属性,python,gtk3,pygobject,pango,Python,Gtk3,Pygobject,Pango,我有以下使用pygtk的代码: attr = pango.AttrList() attr.change(pango.AttrSize(( 50 * window_height / 100) * 1000, 0, -1)) attr.change(pango.AttrFamily("Sans", 0, -1)) attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)) attr.change(pango.AttrFore

我有以下使用pygtk的代码:

attr = pango.AttrList()
attr.change(pango.AttrSize((
            50 * window_height / 100) * 1000, 0, -1))
attr.change(pango.AttrFamily("Sans", 0, -1))
attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1))
attr.change(pango.AttrForeground(65535, 65535, 65535, 0, -1))

self.label.set_attributes(attr)
我试图将其移植到pygobject,但是没有类Pango.attrfamine、Pango.AttrWeight和Pango.AttrForeground(并且我无法实例化Pango.AttrSize)

问题是:如何使用,以及如何通过Instropection


我知道我可以这样做,但是我。使用属性将使事情变得更简单。我想知道这里发生了什么!我已经花了很多时间试图解决这个问题。

编辑:由于方法
覆盖\u font
已被弃用,您应该使用CSS,如本页所述-

剩下的答案留作历史参考

我不知道为什么那样不行

这里有一个方法

def set_global_styles(self, editor_widget):
    pango_context = editor_widget.create_pango_context()
    font_description = pango_context.get_font_description()
    increase = 14 #pt 14
    font_size = 1024*increase
    font_description.set_size(font_size)
    editor_widget.override_font(font_description)
到目前为止,这是我找到的最简单的方法。 迟回答,但迟回答总比不回答好

以防Pango和使用上面的代码需要一些资源。 我不确定Pango的所有文档是否都适用于gtk3,但它对我有效

在其他对象中。

从中,我发现它运行时没有运行时错误:

    from gi.repository import Pango

    ren = Gtk.CellRendererText()
    ren.set_property('alignment', Pango.Alignment.RIGHT)
虽然在我的代码中,这并没有使内容向右对齐,但我的代码中可能还有另一个错误。这里最重要的是,上面的代码似乎是pygtk的翻译,比如
import pango
和:
pango.ALIGN_RIGHT


这不是OP的完整答案,但希望离它更近一步。

你有什么收获吗?我也有同样的问题。FIY,这是一个相关的问题:(自2014年以来未变)这个问题尚未解决。但是你可以通过使用新的CSS系统来解决这个问题:
#mylabel{color:blabla;etc;}
,设置
self.label.set_name(“mylabel”)
然后导入CSS文件
Gtk.CssProvider.load_from_文件(Gtk.CssProvider\u get_default(),file)
。不要使用此代码<代码>覆盖字体已被弃用。