S
Sylvie
Hi group,
I try to use radio buttons in my Gtk2 perl script so that when the user
clicks one a variable changes of value and a sub routine is called. This is
my code:
my $button1 = Gtk2::RadioButton->new(undef,"Radio Button 1");
$button1->signal_connect("toggled" => sub { $value = "button1";
sighandler(); },"Radio Button 1" );
$vbox->pack_start($button1, TRUE, TRUE, 0);
$button1->set_active(TRUE);
$button1->show;
my @group = $button1->get_group;
my $button2 = Gtk2::RadioButton->new_with_label(@group,"Radio Button 1");
$button2->signal_connect("toggled" => sub {$value = "button2";
sighandler(); },"Radio Button 1" );
$vbox->pack_start($button2, TRUE, TRUE, 0);
$button2->show;
sub sighandler {
print "DEBUG: value = $value\n";
}
The problem I'm having is that everytime a new radio button is toggled, the
sighandler gets called twice: once for the old value of the radio button and
one for the new value. So if I start the script and click on Radio Button 2
it prints:
DEBUG: value = Radio Button 1
DEBUG: value = Radio Button 2
If I now change back to Radio Button 1 I see:
DEBUG: value = Radio Button 2
DEBUG: value = Radio Button 1
I tried naming the buttons the same ($button1 -> $button and $button2 ->
$button) but that didn't matter. What am I doing wrong and how can I fix
this?
Thanks in advance, Sylvie.
I try to use radio buttons in my Gtk2 perl script so that when the user
clicks one a variable changes of value and a sub routine is called. This is
my code:
my $button1 = Gtk2::RadioButton->new(undef,"Radio Button 1");
$button1->signal_connect("toggled" => sub { $value = "button1";
sighandler(); },"Radio Button 1" );
$vbox->pack_start($button1, TRUE, TRUE, 0);
$button1->set_active(TRUE);
$button1->show;
my @group = $button1->get_group;
my $button2 = Gtk2::RadioButton->new_with_label(@group,"Radio Button 1");
$button2->signal_connect("toggled" => sub {$value = "button2";
sighandler(); },"Radio Button 1" );
$vbox->pack_start($button2, TRUE, TRUE, 0);
$button2->show;
sub sighandler {
print "DEBUG: value = $value\n";
}
The problem I'm having is that everytime a new radio button is toggled, the
sighandler gets called twice: once for the old value of the radio button and
one for the new value. So if I start the script and click on Radio Button 2
it prints:
DEBUG: value = Radio Button 1
DEBUG: value = Radio Button 2
If I now change back to Radio Button 1 I see:
DEBUG: value = Radio Button 2
DEBUG: value = Radio Button 1
I tried naming the buttons the same ($button1 -> $button and $button2 ->
$button) but that didn't matter. What am I doing wrong and how can I fix
this?
Thanks in advance, Sylvie.