GTK+中文社区(gtk.awaysoft.com)

 找回密码
 马上加入

QQ登录

只需一步,快速开始

查看: 3636|回复: 1

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

[复制链接]
  • TA的每日心情
    奋斗
    2015-10-16 12:17
  • 签到天数: 401 天

    连续签到: 1 天

    [LV.9]以坛为家II

    发表于 2013-9-19 15:41:35 | 显示全部楼层 |阅读模式

       文字描述不出来  所以直接上图:

         











    将文件保存为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[6];
        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;
    }




    运行如图所示:





    *滑块验证:
    您需要登录后才可以回帖 登录 | 马上加入

    本版积分规则

    申请友链|Archiver|小黑屋|手机版|GTK+中文社区 ( 粤ICP备13080851号 )

    我要啦免费统计

    GMT+8, 2024-12-22 01:10 , Processed in 0.023768 second(s), 8 queries , Redis On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表