该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
gint close_application( GtkWidget *widget, GdkEvent *event,gpointer data ) {
gtk_main_quit ();
return FALSE;
}
int main( int argc, char *argv[] ) {
/*GtkWidget 是构件的存储类型 */
GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *button;
GtkWidget *separator;
GSList *group;
/*这个函数在所有的GTK程序都要调用。参数由命令行中解析出来并送到该程序中。*/
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);//初始化 创建一个新窗口
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (close_application), NULL);//设置一个处理函数来立即退出GTK
gtk_window_set_title (GTK_WINDOW (window), "radio buttons");//新建窗体名
gtk_container_set_border_width (GTK_CONTAINER (window), 0);//设置窗口边框的宽度
box1 = gtk_vbox_new (FALSE, 0);//新建一个组装盒 (vbox ,hbox)
gtk_container_add (GTK_CONTAINER (window), box1);//把组装盒放入到主窗体中
gtk_widget_show (box1);//显示创建组装盒
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_radio_button_new_with_label (NULL, "button1");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));//添加到组中的按钮必*须调用此函数才可以将其几个按钮关联起来
button = gtk_radio_button_new_with_label (group, "button2");//创建第二个按钮
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);//多个按钮组合到一起到一起后只能有一个按钮被使用 发出一个信号
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), "button3");
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
gtk_widget_show (button);
separator = gtk_hseparator_new ();//分割线
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
gtk_widget_show (separator);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);
button = gtk_button_new_with_label ("close");//退出按钮
g_signal_connect_swapped (G_OBJECT (button), "clicked",G_CALLBACK (close_application), window);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}