[pygtk] I must be missing something - can't get label of a menu item

Gustavo J. A. M. Carneiro gjc at inescporto.pt
Sat Oct 16 06:04:39 WST 2004

Sex, 2004-10-15 às 15:20 -0300, Christian Robottom Reis escreveu:
> On Thu, Oct 14, 2004 at 04:24:17PM -0500, Skip Montanaro wrote:
> > I have an option menu full of radio menu items defined via Glade.  At
> > runtime I'd like to get a string value out of the menu which
> > corresponds to the selected item.  The displayed label would be fine
> > (I'll force it to be unique) but I can't figure out how to get at it.
> > I'm trying to avoid enumerating all the menu item objects in my code
> > (e.g. wtree.get_widget("menu-item-N")), preferring instead to leave
> > all those definitions to the glade user.
> Johan's suggested the FAQ, and that's full of warnings that should be
> heeded. One alternative which I use daily is, instead of relying on the
> label, doing a set_data() on the menuitems as you put them into the
> menu, and then using get_data() to grab it back. I can get example code
> if that's not clear enough.
> There's one catch -- you can't use None given get_data() returns None by
> default; just use a ValueUnset dummy class to work around that, though.

  Actually, I think the only clean solution is to use
gtk.OptionMenu.get_history(), as index to a list of strings, or whatever
you want associated with each option.

> Take care,
> --
> Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
The universe is always one step beyond logic

More information about the pygtk mailing list