Re: Getting the name of a button.



muppet said:

Eric Depagne said:
I would like to know if it is possible to get the label of the button on
which
one clicks and assign it to let say $Name.

a button is a container, and when you create a button with new_with_label
(which is what Gtk::Button->new (string) does for you), the container has one
child, a GtkLabel.

try this (danger, will robinson, untested code!):

   # fetch the button's contained child
   $label = $button->get_child; # may be ->child, i don't remember for sure
   die "child isn't what i thought it was"
        unless 'Gtk::Label' eq ref $button;
   $label->set_text ($new_text);

(at least for Gtk2, i assume 1 does as well)

there's a method for getting the label of a button:
     $button->get_label
that should work for you purpose. if the button doesn't have a label it will
return undef.
http://developer.gnome.org/doc/API/2.0/gtk/GtkButton.html#gtk-button-get-label

i.e.:
foreach (@buttons)
{
    $_->signal_connect( clicked => sub {
        $btn = shift;
        $Name = $btn->get_label;
        ...
    } );
}

once again this is untested/compiled code but outside of syntax errors and
type-o's it should/will work.

-rm



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