Python GTK+ widget name

How do I get a widget’s “name”?

When I define a GUI using Glade, I can “name” the widgets of the window but how do I recover that property when I have a widget object instance?

I’ve tried get_property(), get_name() and $ to no avail.

Update: I am using GtkBuilder file format (i.e. XML format).

Resolution: a fix I have used: use the set_property("name", name) method on the widget just after getting it from GtkBuilder.

I use the class-method form, which works for me:



PyGtk: gtk.Buildable.get_name

Gtk3: Gtk.Buildable.get_name

Quote from gtk2 GtkBuilder:

Prior to GTK+ 2.20, gtk.Builder was setting the “name” property of
constructed widgets to the “id” attribute. In GTK+ 2.20 or newer, you
have to use gtk.Buildable.get_name() instead of gtk.Widget.get_name()
to obtain the “id”, or set the “name” property in your UI definition.


There were some reported bugs where GtkBuilder sets the widget name to be the builder ID, or doesn’t set it at all. See Ubuntu and GNOME bugs. I have no idea why the bugs says that it sets the ID instead of the name as I’ve only ever seen the name not set.

Leave a Comment