如何使用 Gtk.Widget.set_template()

ely*_*ya5 5 python gtk

我正在尝试使用该Gtk.Widget.set_template()方法,但我不确定如何在没有Gio.Resource 的情况下使用它。我正在使用 python3 和 gi.repository。

假设我有一个 foowidget.ui,然后我想上一堂课:

class FooWidget(Gtk.Box):
    Gtk.Box.__init__(self)
    #set_template here with 'foowidget.ui'
    self.init_template()
Run Code Online (Sandbox Code Playgroud)

ely*_*ya5 1

目前无法set_template与 python 一起使用。这里有一个未解决的错误。

编辑: 到目前为止,可以在 python 中使用模板。它看起来像这样:

from gi.repository import Gtk


@Gtk.Template(resource_path='/path/to/resource/window.ui')
class Window(Gtk.Window):
    __gtype_name__ = 'Window'
    button = Gtk.Template.Child()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    @Gtk.Template.Callback('clicked')
    def on_button_clicked(self, widget):
         pass

Run Code Online (Sandbox Code Playgroud)