问题
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