用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

Hello, GTK!

2016-11-10 作者:老赵爱编程举报

[c]代码库

/**
 * hellogtk.c
 * gtk-3.0
 */
#include <gtk/gtk.h>

/* a callback function */
static void hello (GtkWidget *widget, gpointer data)
{
    g_print ("%s\n", (char *)data);
}

int main (int argc, char* argv[])
{
    /* first thing first */
    gtk_init (&argc, &argv);

    /* window object */
    GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Hello, GTK!");
    gtk_widget_set_size_request (window, 320, 200);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
    gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS);
    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (gtk_main_quit), NULL);
    gtk_widget_show (window);

    /* a container */
    GtkWidget *box = gtk_box_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), box);
    gtk_widget_show (box);

    /* two buttons */
    GtkWidget *button1, *button2;
    button1 = gtk_button_new_with_label ("Hello, World!");
    g_signal_connect (button1, "clicked", G_CALLBACK(hello), "Hello, World!");
    gtk_box_pack_start(GTK_BOX (box), button1, TRUE, FALSE, 0);
    gtk_widget_show (button1);

    button2 = gtk_button_new_with_label ("Hello, GTK!");
    g_signal_connect (button2, "clicked", G_CALLBACK(hello), "Hello, GTK!");
    gtk_box_pack_start (GTK_BOX (box), button2, TRUE, FALSE, 0);
    gtk_widget_show (button2);

    /* main loop start */
    gtk_main ();

    return 0;
}

[代码运行效果截图]


Hello, GTK!

[源代码打包下载]




分享到:
更多

网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。