Re: Grouping Toggle Buttons

On Jul 5, 2005, at 2:04 PM, Jens Luedicke wrote:

I want to group toggle buttons so that only one is active at a time and clicking another one in the group de-toggles all others. Like Radiobuttons.

Any ideas?

Use RadioButtons.

/me ducks

No, seriously. ToggleButton, from which RadioButton inherits, has an object property named "draw_indicator". In modern times this would be a style property, but it's apparently a holdover, and you can still use it in your code to make your RadioButton look like a ToggleButton, for whatever odd reason you may have (insert standard disclaimer about how only themes are supposed to be in charge of this sort of thing).

  #!/usr/bin/perl -w
  use strict;
  use Glib qw(FALSE);
  use Gtk2 -init;

  my $window = Gtk2::Window->new;
  $window->signal_connect (destroy => sub { Gtk2->main_quit });
  my $vbox = Gtk2::VBox->new;
  $window->add ($vbox);
  my $rb = undef;
  foreach (qw(one two three four)) {
      $rb = Gtk2::RadioButton->new ($rb, $_);
      $rb->set (draw_indicator => FALSE); # i'm evil
      $vbox->add ($rb);
      $rb->signal_connect (toggled => sub {
print $_[0]->get_label." ".($_[0]->get_active ? "on" : "off")."\n";
  Gtk2->main ;

"it's hard to be eventful when you have this much style."
   - me, rationalizing yet another night of sitting at home.

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