I’ve got a GTK window with some widgets on it. There are a bunch of expanders on there, which all have the same activate signal handler. In this handler, I’d like to get the name of the widget object.
def exItem_activated (self, widget, data=None):
for i in range (0, 15):
self.builder.get_object ('exItem' + (str)(i + 1)).set_expanded (False)
widget.expanded = True
print widget.name
widget.name does not work, however; AttributeError: 'Expander' object has no attribute 'name'.
So basically, when expander2 is clicked, I want to get “expander2” as a string. When expander14 is clicked, I want to get “expander14” as a string. Is there any way to do this?
If this can’t (easily) be done, it would also be an acceptable if I could just get some other property by which I could tell which widget was clicked.
The corresponding method is called
get_name()as far as I understand, eg.:Edit: for glade-based UI with gtk 2.20+ the
gtk.Buildable.get_name()method should be used instead ofgtk.Widget.get_name()since widget names are stored inidattribute of UI definition.