Tuesday, December 10, 2013

GTK+ exercise: GtkBox - A container box

Example of using GtkBox.
GtkBox
Example of using GtkBox
helloGtkBox.c
#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *label1, *label2, *label3;
    GtkWidget *box;
    
    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    
    gtk_window_set_title(GTK_WINDOW(window), 
        "Hello Raspberry Pi - GTK+ exercise"); 
        
    //terminate the application when the GtkWindow is destroyed
    g_signal_connect (window, "destroy", 
        G_CALLBACK(gtk_main_quit), NULL);
    
    label1 = gtk_label_new("Label 1");
    label2 = gtk_label_new("Label 2");
    label3 = gtk_label_new("Label 3");
    
    box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
    
    gtk_box_pack_start(GTK_BOX(box), label1, TRUE, FALSE, 5);
    gtk_box_pack_start(GTK_BOX(box), label2, TRUE, FALSE, 5);
    gtk_box_pack_start(GTK_BOX(box), label3, TRUE, FALSE, 5);
    
    gtk_container_add(GTK_CONTAINER(window), box);
    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
}


No comments: