How can I retrieve from a GTK Builder the name of

2019-07-20 22:04发布

This question already has an answer here:

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条回答
一纸荒年 Trace。
2楼-- · 2019-07-20 22:25

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"
查看更多
登录 后发表回答