Multiple Buttons

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

# 3.3. Multiple Buttons

    #!/usr/cogent/bin/gamma

    /* Example: Multiple buttons.
     * This example creates several identical buttons
     * and adds them to a horizontal button box.
     */

    /* Initialize Cogent interprocess communication.*/
    init_ipc("a", "aq");

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

    /* Create a GtkWindow with a title.*/
    window = new(GtkWindow);
    window.set_border_width(20);
    window.set_default_size(300,100);
    window.set_title("Hello Buttons!");

    /* Create a horizontal button box, add it to the window.*/
    box1 = new(GtkHButtonBox);
    window.add(box1);

    /* Create some buttons, make callbacks for them, and add
     * the buttons to the box.
     */
    for (i=1;i<=3;i++)
        {
          button = new(GtkButton);
          button.label = string("Button ",i);
          button.signal("clicked",#hello());
          box1.add(button);
        }

    /* Make an exit button. */
    button = new(GtkButton);
    button.label = string("Exit");
    button.signal("clicked",#gtk_main_quit());
    box1.add(button);

    /*
     * Show everything.
     */
    window.show_all();

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

Prev | Home | Next
Add a Button with a Callback | Up | Packing Widgets in Boxes

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