[pygtk] PyGtk / Glade - how to get name of textEntry
Olaf Devik
olaf.devik at mollefaret.no
Wed Sep 28 05:12:35 WST 2011
Thanks, gtk.Buildable.get_name(widget) did the trick. I now have a list
of all objects as created by the glade file, and I can get same
information within eg a dialog/notebook.
Regards
Olaf Devik
e-mail: olaf.devik at mollefaret.no
mobile: +47 911 70 849
Den 2011-09-27 22:21, skrev Dieter Verfaillie:
> 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