Add a Button with a Callback

Gamma/GTK: Using Gamma™ with GTK, Version 0.9
Prev | Chapter 3. Building Applications - a Tutorial | Next

# 3.2. Add a Button with a Callback

    #!/usr/cogent/bin/gamma

    /* Example: Button-controlled "Hello world!"
     * This example creates a button in a window that calls
     * a "Hello, world!" function and then quits GTK,
     * demonstrating the use of callbacks.
     */

    /* Initialize Cogent interprocess communication, which is
     * necessary for using Gamma/GTK.
     */
    init_ipc("a", "aq");

    /* Write a Hello, world! function. */
    function hello()
    {
      princ("Hello, world!\n");
    }

    /* Create a GtkWindow and a GtkButton. */
    window = new(GtkWindow);
    window.set_border_width(20);
    button = new(GtkButton);
    button.label = " Click me! ";

    /* Add callbacks to the button to execute the
     * "Hello, world!" function and quit.
     */
    button.signal("clicked",#hello());
    button.signal("clicked",#gtk_main_quit());

    /* Add the button to the window, and show them both.*/
    window.add(button);
    window.show_all();

    /* Enter the GTK main processing loop.*/
    gtk_main();

Prev | Home | Next
Building Applications - a Tutorial | Up | Multiple Buttons

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.