Re: Gtk2::MenuItem get_label?



Grant McLean wrote:

The Gtk2::MenuItem is derived from the Gtk::Bin class, so you can
use the ->child method to get the label object out.  Then you can use
the ->get_label method to get the text of the label.

  my $text = $menu_item->child->get_label;

Well, doesn't really work for me:

my $menu = $glade->get_widget($name1)->get_menu;
my @items = $menu->get_children;
for my $item (@items) {
    print "item=", $item, "\n";
    print "  child=", ($item->child ? $item->child : "undef"), "\n";
print " label=", ($item->child ? $item->child->get_label : "undef"), "\n";
}

Output ($name1 is a Glade-2 generated option menu with 2 items "None" and "Fade":

1. "None" selected

item=Gtk2::MenuItem=HASH(0x8d68df4)
  child=undef
  label=undef
item=Gtk2::MenuItem=HASH(0x8d690f4)
  child=Gtk2::AccelLabel=HASH(0x8d82e10)
  label=Fade

2. "Fade" selected

item=Gtk2::MenuItem=HASH(0x8d68e18)
  child=Gtk2::AccelLabel=HASH(0x8758d4c)
  label=None
item=Gtk2::MenuItem=HASH(0x8d69118)
  child=undef
  label=undef

So it seems I can only retrieve the label from menu items which are *not* currently selected? Strange.

Martin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]