Problems getting the child of a Gtk::OptionMenu



hi,

I am trying to get the label of a MenuItem in a Gtk::OptionMenu.

I know it would be easier to just add a hash key for the string in to widgets, but
I want to use Gtk to do it.

what I have:

  my $optionmenu = new Gtk::OptionMenu;
  my $menu = new Gtk::Menu;
  $menu->show;
  $optionmenu->set_menu($menu);
  $optionmenu->show;

   foreach (qw(opt1 opt2 opt3 opt4)) {
    my $menu_item = new Gtk::MenuItem ( $_ );
    $menu_item->signal_connect('activate', \&callback);
    $menu_item->show;
    $menu->append( $menu_item );
  }

sub callback {
 my ($widget) = @_;
 print "undefined child!\n" unless defined $widget->child;
}

As a Gtk::MenuItem Inherits from Gtk::Bin it has the method child() .
However the callback above will result in a undefined child.

The same happens with $widget->children() .

Am I missing something?

shouldn't there be a Gtk::Label instead of undef?


Regards,

Raul Dias







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