Maybe you could use a closure:

   foreach (qw(opt1 opt2 opt3 opt4)) {
    my $menu_item = new Gtk::MenuItem ( $_ );
    $menu_item->signal_connect('activate', sub { print "I have a
child\n" if defined $menu_item->child});
    $menu->append( $menu_item );


From: Raul Dias <chaos swi com br>
To: gtk-perl-list gnome org
Subject: Problems getting the child of a Gtk::OptionMenu


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;

   foreach (qw(opt1 opt2 opt3 opt4)) {
    my $menu_item = new Gtk::MenuItem ( $_ );
    $menu_item->signal_connect('activate', \&callback);
    $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?


Raul Dias


John McDermott, Writer and Consultant
J-K International, Ltd.
V +1 505/377-6293  F +1 505/377-6313
jjm jkintl com

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