Saturday, December 28, 2013

Example of using GtkBox

GtkBox
GtkBox

#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 *myImage;
    GtkWidget *myButton;
    GtkWidget *box;

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

    /*
    warning: 
        ‘gtk_vbox_new’ is deprecated 
        Use 'gtk_box_new' instead
    */
    //box = gtk_vbox_new(FALSE, 0);
    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

    myImage = gtk_image_new_from_file ("Linux.png");

    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_box_pack_start(GTK_BOX(box), myImage, TRUE, TRUE, 5);
    gtk_box_pack_end(GTK_BOX(box), myButton, TRUE, TRUE, 5);

    gtk_container_add(GTK_CONTAINER (window), box);
    gtk_widget_show_all (window);

    gtk_main();
    return(0);
}