How can I retrieve from a GTK Builder the name of an object? [duplicate]

核能气质少年 提交于 2019-12-24 04:32:46

问题


How do I get the name of a Gtk.Widget retrieved from a Builder object?

I specifically mean the name seen in Glade (eg: button1), not the name of the class (GtkWindow).

This question is exactly the same as this one, but for Python with GObject introspection.


回答1:


You can't use the get_name method inherited from Gtk.Widget. Instead, you have to use the get_name method defined in Gtk.Buildable, like this:

button = builder.get_object("button1")
print(Gtk.Buildable.get_name(button)) # prints "button1"


来源:https://stackoverflow.com/questions/15393120/how-can-i-retrieve-from-a-gtk-builder-the-name-of-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!