Python 未定义PyGObject模板子项
我已经使用以下规范为我的GTK项目创建了一个Glade UI:Python 未定义PyGObject模板子项,python,gtk,glade,pygobject,Python,Gtk,Glade,Pygobject,我已经使用以下规范为我的GTK项目创建了一个Glade UI: <?xml version="1.0" encoding="UTF-8"?> <!-- Generated with glade 3.22.1 --> <interface> <requires lib="gtk+" version="3.20"/> <template class="Pages" parent="GtkBox"> <property
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="Pages" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="page_title">
<property name="visible">True</property>
<property name="label" translatable="yes">Title</property>
<attributes>
<attribute name="weight" value="normal"/>
<attribute name="scale" value="1.5"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</template>
</interface>
然而,输出总是
<class 'gi._gtktemplate.Child'>
AttributeError: 'Child' object has no attribute 'set_text'
它的输出是
所以PyGObject发生了一些非常奇怪的事情。我做错什么了吗?感谢您的帮助。请使用
GtkTemplate.Child()
而不是Gtk.Template.Child()
编辑:Gtk.Template.Child()
仅适用于最新的Gtk+3版本。您应该将其更新到最新版本,或者,您可以在gi_composites.py
补丁文件中使用GtkTemplate.Child()
有关更多信息,请阅读
/your_project/src
目录第162行的gi_composites.py
文档,使用GtkTemplate.Child()
而不是Gtk.Template.Child()
编辑:Gtk.Template.Child()
仅适用于最新的Gtk+3版本。您应该将其更新到最新版本,或者,您可以在gi_composites.py
补丁文件中使用GtkTemplate.Child()
有关更多信息,请阅读
/your_project/src
目录第162行的gi_composites.py
文档。据我所知,链接的示例使用page_title=Gtk.Template.Child(“page_title”)
,如果变量名不同于子id,则使用Gtk.Template.Child
的参数。我也尝试了page\u title=Gtk.Template.Child(“page\u title”)
,但没有任何区别。如果资源路径=
错误,我们会看到任何错误吗?你能用Gtk.Builder验证一下吗..从文件中添加(…
?将其从resource\u path='/com/bscubed/App/ui/pages.ui'
更改为resource\u path='/com/bscubed/App/ui/paes.ui'
会导致错误gi.repository.GLib。错误:g-resource-error-quark:com/bscubed/App/ui/paes.ui上的资源不存在(0)
。在做了一些挖掘之后,我相信我遇到的bug与Yes有关,听起来很相似,值得检查使用过的版本。链接的示例使用page\u title=Gtk.Template.Child(“page\u title”)
?据我所知,如果变量名不同于子id,则使用Gtk.Template.Child
的参数。我尝试了page\u title=Gtk.Template.Child(“page\u title”)
也一样,但没有什么区别。如果资源路径=
错误,我们会看到任何错误吗?你能用Gtk.Builder.从文件中添加吗(…
?将其从resource\u path='/com/bsubed/App/ui/pages.ui'
更改为resource\u path='/com/bsubed/App/ui/paes.ui'
会导致错误gi.repository.GLib。错误:g-resource-error-quark:com/bsubed/App/ui/paes.ui上的资源不存在(0)
。在做了一些挖掘之后,我相信我遇到的bug与Yes有关,听起来很相似,值得检查使用过的版本。
<class 'gi._gtktemplate.Child'>
AttributeError: 'Child' object has no attribute 'set_text'
from gi.repository import Gtk
from .pages import Pages
@Gtk.Template(resource_path='/com/bscubed/App/ui/window.ui')
class MainWindow(Gtk.ApplicationWindow):
__gtype_name__ = 'MainWindow'
toolbar_stack = Gtk.Template.Child()
content_stack = Gtk.Template.Child()
start_button = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.start_button.connect("clicked", self.next_page)
print(type(self.start_button))
def next_page(self, button):
self.content_stack.set_visible_child_name("pages")
self.toolbar_stack.set_visible_child_name("pages_toolbar")