【问题标题】:GtkRadioButton set active and deactiveGtk 单选按钮设置激活和非激活
【发布时间】:2010-08-09 06:05:33
【问题描述】:

我的 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");

我阅读了 man 但没有找到解决方案,如何使一次只有一个单选按钮处于活动状态。

谢谢

【问题讨论】:

    标签: radio-button gtk


    【解决方案1】:

    来自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;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 2013-07-14
      • 2016-06-27
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多