Libglade is a library that takes an XML description of an interface (built either by Glade or by hand), parses it, and generates the appropriate widgets for you.


Using Libglade is very easy. It basically consists of two simple steps. The first step is to call a function which parses the interface and creates the widgets. The second is to connect all the signals (i.e. events such as clicking on a button) to the appropriate callback functions. Below is an example that uses to build a functioning program. It includes one predefined callback function (namely, gtk_main_quit) and one user defined callback function.

/* This program displays a simple window and has a simple callback for
 * when the OK button is clicked.

#include <gtk/gtk.h>
#include <glade/glade.h>

ok_button_clicked (GtkWidget *widget, gpointer user_data)
  printf ("Thanks for trying out my program.\n");
  gtk_main_quit ();

main (int argc, char *argv[])
  GladeXML  *main_window;
  GtkWidget *widget;

  gtk_init (&argc, &argv);

  /* load the interface */
  main_window = glade_xml_new ("", NULL, NULL);

  /* connect the signals in the interface */

  /* Have the ok button call the ok_button_clicked callback */
  widget = glade_xml_get_widget (main_window, "OKButton");
  g_signal_connect (G_OBJECT (widget), "clicked",
                    G_CALLBACK (ok_button_clicked),

  /* Have the delete event (window close) end the program */
  widget = glade_xml_get_widget (main_window, "MainWindow");
  g_signal_connect (G_OBJECT (widget), "delete_event",
                    G_CALLBACK (gtk_main_quit), NULL);

  /* start the event loop */
  gtk_main ();

  return 0;

Language bindings

Issues specific to the various language bindings (including compilation instructions) can be found at one of the below links:

Learning more

To help you get started, I am including several examples. These examples correspond to the .glade files covered in the Glade section of this tutorial.

There are many other things you can do with Libglade. To save on application startup time in larger programs, you can use multiple .glade files (and only parse the ones you need when you first need them) or have Libglade only build the windows you need from a .glade file (leaving the rest to be built when they are needed later). You can also have Libglade only build a small part of the interface for your program and build the rest by hand (referred to as "Embedding" Libglade interfaces). Libglade can also be extended to handle custom widgets. For more information about these and other options, check out the Libglade reference manual.