function setup_dialog() { $dialog = new GtkDialog(); $dialog->vbox->pack_start(new GtkLabel('Which platform are you using: ')); $radio0 = setup_radio(null, 'radio button 0', '100'); // note 1 $radio1 = setup_radio($radio0, 'Windows', 'win'); $radio2 = setup_radio($radio0, 'Mac', 'mac'); $radio3 = setup_radio($radio0, 'Linux', 'linux'); // pack them inside vbox $dialog->vbox->pack_start($radio1, 0, 0); // note 2 $dialog->vbox->pack_start($radio2, 0, 0); // note 2 $dialog->vbox->pack_start($radio3, 0, 0); // note 2 $dialog->vbox->pack_start($hbox2 = new GtkHBox()); $button_ok = GtkButton::new_from_stock(Gtk::STOCK_OK); $button_ok->set_size_request(87, 33); $hbox2->pack_start(new GtkLabel()); $hbox2->pack_start($button_ok, 0); $button_ok->connect('clicked', 'on_ok_button', $dialog); $dialog->set_has_separator(false); $dialog->action_area->set_size_request(-1, 1); $dialog->show_all(); global $selected_radio, $selected_radio_value; $selected_radio = $selected_radio_value = ''; $dialog->run(); $dialog->destroy(); global $response; $response->set_text("{$selected_radio} ({$selected_radio_value})"); // note 5 }
$window = new GtkWindow(); $window->set_size_request(400, 200); $window->connect_simple('destroy', array('Gtk', 'main_quit')); $window->add($vbox = new GtkVBox()); // display title $title = new GtkLabel(); $title->set_markup('<span color="blue" font_desc="Times New Roman Italic 12"> Button Group Demo</span>'); $vbox->pack_start($title); // setup grouped radio buttons $radio1 = setup_radio(null, 'radio button 1', '101'); // note 1 $radio2 = setup_radio($radio1, 'radio button 2', '102'); // note 2 $radio3 = setup_radio($radio1, 'radio button 3', '103'); // pack them inside vbox $vbox->pack_start($radio1, 0, 0); $vbox->pack_start($radio2, 0, 0); $vbox->pack_start($radio3, 0, 0); // add a status area $vbox->pack_start($status_area = new GtkLabel('Click a Button')); // function to simplify the display of grouped radio buttons function setup_radio($radio_button_grp, $button_label, $button_value) { // note 3 $radio = new GtkRadioButton($radio_button_grp, $button_label); $radio->connect('toggled', "on_toggle", $button_value); // note 4 return $radio; }