[pygtk] PyGtk / Glade - how to get name of textEntry
Dieter Verfaillie
dieterv at optionexplicit.be
Wed Sep 28 04:21:50 WST 2011
On Tue, 27 Sep 2011 22:01:06 +0200, Olaf Devik wrote:
> Thanks for tip Dieter, but I have tried gtk.Widget.get_name(widget)
> function, returns eg GtKEntry for a TextEntry field and GtkLabel for
> a
> label, ie the same as I get when using widget.get_name(). Code:
>
> print j.get_name()
> print gtk.Widget.get_name(j)
>
> Both returns GtkEntry when run on a TextEntry.
>
> I am after the name of the TextEntry as given in Glade, such as
> enTime or enDate.
>
> Any ideas?
Heh, delved in my archives and it seems I've been bitten by this
almost 2 years ago. Then promptly forgot all about it. Anyway,
here you go:
If you're still using libglade (assuming the ui variable contains
a valid glade document):
>>> glade = gtk.glade.xml_new_from_buffer(ui, len(ui))
>>> glade.get_widget('label1').name
label1
If you're still using GtkBuilder (assuming the ui variable contains
a valid GtkBuilder document, created by Glade):
>>> builder = gtk.Builder()
>>> builder.add_from_string(ui)
>>> label = builder.get_object('label1')
>>> gtk.Buildable.get_name(label)
label1
More info on http://developer.gnome.org/gtk/2.24/GtkBuilder.html
search for the text "Prior to 2.20".
mvg,
Dieter
More information about the pygtk
mailing list