Adsense code (2021-10-05)

Thursday, December 26, 2013

"Hello World" of GTK+ 3 with C language

"Hello World" of GTK+ 3 with C language
"Hello World" of GTK+ 3 with C language
hello.c
#include <gtk/gtk.h>

static void myButtonClicked(GtkWidget *widget, gpointer   data)
{
    g_print("Button clicked: Hello GTK+\n");
}

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *myButton;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);

    myButton = gtk_button_new_with_label("Hello GTK+ from Linux-Buddy");
    g_signal_connect(myButton, "clicked", 
        G_CALLBACK(myButtonClicked), NULL);

    g_signal_connect (window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_add(GTK_CONTAINER (window), myButton);
    gtk_widget_show(myButton);
    gtk_widget_show(window);

    gtk_main();
    return(0);
}
Compile with:
gcc hello.c -o hello `pkg-config --cflags --libs gtk+-3.0`
Run:
./hello