我的第一隻GTK+程式 helloworld!

程式碼如下 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <gtk/gtk.h>
 
static void destroy(GtkWidget *widget, gpointer data) {
    gtk_main_quit();
}
 
int main(int argc, char *argv[]) {
    GtkWidget *window;
    GtkWidget *label;
 
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
    label = gtk_label_new("hello world");
    gtk_container_add(GTK_CONTAINER(window), label);
    gtk_container_set_border_width(GTK_CONTAINER(window), 15);
    gtk_window_set_title(GTK_WINDOW(window), "hello world");
    gtk_widget_show(label);
    gtk_widget_show(window);
    gtk_main();
 
    return 0;
}

這是執行結果 :

GTK+我不是那麼懂! 還是初學者.請多多指教!

參考 : GTK+ 2.0 Tutorial