by Daniel Pimentel — Mon 09 September 2013

Glade is a user interface designer for GTK+ applications. It is used to rapidly prototype GTK+ and GNOME applications. It provides a framework that allows an application author to dynamically add, remove, and modify widgets. It is done in a very simple, yet powerful manner that lets even novice developers design a user interface in a short time. Glade saves a user interface description to an XML file, and this can be dynamically used in your application using GtkBuilder. By using GtkBuilder, you are left with more maintainable code, with a separation between the applications design and its behavior. GtkBuilder is especially useful, because the XML file is loaded at runtime, allowing you to make tweaks to your user interface without having to recompile your application.


 * Compile me with:
 *   gcc -o tut tut.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0)

#include <gtk/gtk.h>

main( int    argc,
      char **argv )
    GtkBuilder *builder;
    GtkWidget  *window;
    GError     *error = NULL;

    /* Init GTK+ */
    gtk_init( &argc, &argv );

    /* Create new GtkBuilder object */
    builder = gtk_builder_new();
    /* Load UI from file. If error occurs, report it and quit application.
     * Replace '' with your saved project. */
    if( ! gtk_builder_add_from_file( builder, '', &error ) )
        g_warning( '%s', error->message );
        g_free( error );
        return( 1 );

    /* Get main window pointer from UI */
    window = GTK_WIDGET( gtk_builder_get_object( builder, 'window1' ) );

    /* Connect signals */
    gtk_builder_connect_signals( builder, NULL );

    /* Destroy builder, since we don't need it anymore */
    g_object_unref( G_OBJECT( builder ) );

    /* Show window. All other widgets are automatically shown by GtkBuilder */
    gtk_widget_show( window );

    /* Start main loop */

    return( 0 );
2000-2016 by Daniel Pimentel under GFDL