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

static gboolean clockCallback(gpointer data);

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

    /* Initialise GTK */
    gtk_init(&argc, &argv);

    /* Create the window */
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT (window), "destroy",
                      GTK_SIGNAL_FUNC(gtk_main_quit),
                      NULL);

    /* Create a label and put it in the window. */
    label = gtk_label_new("This is a label");
    gtk_container_add(GTK_CONTAINER(window), label);

    /* Install a function to be call every 50ms. */
    g_timeout_add(50, clockCallback, label);

    /* Show everything and run the main loop. */
    gtk_widget_show_all(window);
    gtk_main();
    return(0);
}

/* Callback function for timer. */
static gboolean clockCallback(gpointer data)
{
static int _count = 0;
    char buf[16];

    /* Change the contents of the label. */
    sprintf(buf, "%d", _count++);
    gtk_label_set_text(GTK_LABEL(data), buf);

    /* Return true so we're called again. */
    return(TRUE);
}
