白浪 发表于 2013-9-19 15:41:35

glade3教程(六)--微调按扭跟组合框

   文字描述不出来所以直接上图:   http://www.bailangcn.tk/content/uploadfile/201203/thum-f3ccdd27d2000e3f9255a7e3e2c4880020120323151703.jpghttp://www.bailangcn.tk/content/uploadfile/201203/thum-fb5c81ed3a220004b71069645f11286720120323151703.pnghttp://www.bailangcn.tk/content/uploadfile/201203/10fb15c77258a991b0028080a64fb42d20120323151703.png



http://www.bailangcn.tk/content/uploadfile/201203/thum-9eb9cd58b9ea5e04c890326b5c1f471f20120323151703.pnghttp://www.bailangcn.tk/content/uploadfile/201308/thum-ea5e1377274855.pnghttp://www.bailangcn.tk/content/uploadfile/201308/thum-edb41377274855.png
http://www.bailangcn.tk/content/uploadfile/201308/thum-6a081377274855.pnghttp://www.bailangcn.tk/content/uploadfile/201308/22471377274855.png



http://www.bailangcn.tk/content/uploadfile/201203/thum-7afbb1602613ec52b265d7a54ad2733020120323151704.png
将文件保存为spin.glade在code::blocks里面输入以下代码:/*作者:bailangcn时间:2012/3/23作者主页:bailangcn.tk*/#include <gtk/gtk.h>
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *spin;
GtkWidget *combobox;
void set_label1(GtkWidget *widget,gpointer data)
{
    gint text;
    const char buf;
    text=gtk_spin_button_get_value_as_int((GTK_SPIN_BUTTON(spin)));
    sprintf(buf,"%d",text);
    gtk_label_set_text(GTK_LABEL(label1),buf);
}
void set_label2(GtkWidget *widget,gpointer *data)
{
    const char *text;
    text=gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox));
    gtk_label_set_text(GTK_LABEL(label2),text);
}
int main(int argc, char *argv[])
{
    GtkBuilder *builder;
    gtk_init(&argc, &argv);
    GtkWidget *window;
    GtkWidget *button1;
    GtkWidget *button2;    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "spin.glade", NULL);
    window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
    spin = GTK_WIDGET(gtk_builder_get_object(builder,"spinbutton"));
    combobox = GTK_WIDGET(gtk_builder_get_object(builder,"combobox"));
    button1 = GTK_WIDGET(gtk_builder_get_object(builder,"button1"));
    button2 = GTK_WIDGET(gtk_builder_get_object(builder,"button2"));
    label1 = GTK_WIDGET(gtk_builder_get_object(builder,"label1"));
    label2 = GTK_WIDGET(gtk_builder_get_object(builder,"label2"));
    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
    g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
    g_signal_connect(G_OBJECT(button1),"pressed",G_CALLBACK(set_label1),NULL);
    g_signal_connect(G_OBJECT(button2),"pressed",G_CALLBACK(set_label2),NULL);   // gtk_builder_connect_signals(builder, NULL);//自动关联已在 UI 文件配置好的信号如果你不在galde文件里面配置信号这行代码可以不用    g_object_unref(G_OBJECT(builder));
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}



运行如图所示:http://www.bailangcn.tk/content/uploadfile/201203/812749e1a307f38fd0a88b54bea55ff220120323152514.png



白浪 发表于 2013-9-19 15:41:51

顶一下哈
页: [1]
查看完整版本: glade3教程(六)--微调按扭跟组合框