RadioButton problem



Hi,

sometimes it is necessary to change the active RadioButton in an existing 
window. But i always can change from the first to the second button, never 
in the other direction!
What's wrong?

Here the example code:

#####################################################################
#!/usr/bin/perl -w

use Gtk;
use strict;

set_locale Gtk;
init Gtk;

my ($lf, $true, $false,
$window, $vbox, $hbox, $radio, $separator, $button
);

$lf="\n";

$false=0;
$true=1;

$window=new Gtk::Window("toplevel");
$window->set_usize(300, 100);
$window->border_width(10);
$window->set_title("Test RadioButton");
$window->signal_connect("delete_event", sub { Gtk->exit(0); });
$window->realize();

$vbox=new Gtk::VBox($false, 0);
$window->add($vbox);
$vbox->show();

$hbox=new Gtk::HBox($false, 0);
$vbox->pack_start($hbox, $false, $false, 0);
$hbox->show();

$radio=new Gtk::RadioButton("First Button");
$hbox->pack_start($radio, $true, $false, 0);
$radio->show();

$radio=new Gtk::RadioButton("Second Button", $radio);
$hbox->pack_start($radio, $true, $false, 0);
$radio->show();

$separator=new Gtk::HSeparator();
$vbox->pack_start($separator, $true, $true, 0);
$separator->show();

$hbox=new Gtk::HBox($false, 0);
$vbox->pack_start($hbox, $false, $false, 0);
$hbox->show();

$button=new Gtk::Button("Check First");
$button->signal_connect("clicked", sub { radio_active($radio, $false); });
$hbox->pack_start($button, $true, $false, 0);
$button->show();

$button=new Gtk::Button("Check Second");
$button->signal_connect("clicked", sub { radio_active($radio, $true); });
$hbox->pack_start($button, $true, $false, 0);
$button->show();

$window->show();

Gtk->main();
Gtk->exit(0);

sub radio_active {
        my ($widget, $status)= _;
        $widget->set_active($status);
        if($widget->active() == 1) {
                print "Second is active now!", $lf;
        }
        unless($widget->active()) {
                print "First is active now!", $lf;
        }
}
#####################################################################



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