GtkRadioButton设置有效和无效

时间:2010-08-03 08:41:31

标签: radio-button gtk

我的C / gtk +应用程序中有4个gtkradiobuttons。但他们都很活跃。

我的代码:

radio_button1 = gtk_radio_button_new_with_label(radio_list, "radio1"); 
radio_button2 = gtk_radio_button_new_with_label(radio_list, "radio2"); 
radio_button3 = gtk_radio_button_new_with_label(radio_list, "radio3"); 
radio_button4 = gtk_radio_button_new_with_label(radio_list, "radio4");

我读过人但未找到解决方案,怎样才能使一次只有一个radiobutton处于活动状态。

谢谢

1 个答案:

答案 0 :(得分:2)

来自Gtk Docs

void create_radio_buttons (void) {

   GtkWidget *window, *radio1, *radio2, *box, *entry;
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   box = gtk_vbox_new (TRUE, 2);

   /* Create a radio button with a GtkEntry widget */
   radio1 = gtk_radio_button_new (NULL);
   entry = gtk_entry_new ();
   gtk_container_add (GTK_CONTAINER (radio1), entry);


   /* Create a radio button with a label */
   radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
                                                         "I'm the second radio button.");

   /* Pack them into a box, then show all the widgets */
   gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 2);
   gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 2);
   gtk_container_add (GTK_CONTAINER (window), box);
   gtk_widget_show_all (window);
   return;
}