Newbie prob with functions...



HI to all. I am completely new to GTK+ and that is why I am going to tell
you something:
PLEEEEEEAAAAAASSEEEEEEEE HEEEEEELLLLLPPPPP!!

Do u get it?
Well... I am learning all this, so I did... well... I am trying to do a
simple program. This program consists of an entry where the user will enter
his name and when he presses a button next to the entry I want a label
(which I already created) to get the text of the entry and display it there.
Quite simple isn't it, well I cannot do it, so please help. Here is the
code, I know is a lot, but please just tell me how to pass the arguments to
the function showname so that it can display the name in the GtkWidget
nombre.

I placed a comment in the showname functions, and other thing you mighy
think it is not ok just tell me and I will try to improve!

Thanks a lot!!
Nicolas

#include <gtk/gtk.h>

gint destroy (void)
{
    gtk_main_quit();
    return(FALSE);
}

void showname (GtkWidget * nombre)
{
    /* I would like this function to insert in a label (nombre) the text
that the user wrote in the entry (entry)
    I am lost in the sense of how to pass the parameters to this funcions */


    gtk_label_set_text(nombre, "Nicolas");
    return;
}

int main (int argc, char * argv [])
{

    GtkWidget  * window;
    GtkWidget  * table;
    GtkWidget * button;
    GtkWidget  * label;
    GtkWidget * entry;
    GtkWidget * nombre;
    GtkWidget * box;

    gtk_init(&argc, &argv);

    /* Creacion de la Ventana Principal */

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW (window), "X-ProMat");
    gtk_container_border_width(GTK_CONTAINER (window), 25);
    gtk_signal_connect (GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC
(destroy), NULL);


    table = gtk_table_new (3, 3, FALSE);

    label = gtk_label_new("Nombre:");
    entry = gtk_entry_new();
    button = gtk_button_new_with_label("Ingresar");
    nombre = gtk_label_new("");
    box = gtk_hbox_new(TRUE, 5);

    /* How do I pass the parameters over here ??? */
    gtk_signal_connect (GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC
(showname), nombre);

    gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 10);
    gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 10);
    gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 10);

    gtk_widget_show(label);
    gtk_widget_show(entry);
    gtk_widget_show(button);

    gtk_table_attach(GTK_TABLE(table), box, 0, 2, 0, 1, GTK_FILL, GTK_FILL,
0, 0);
    gtk_widget_show(box);

    box = gtk_hbox_new(TRUE, 5);
    gtk_box_pack_start(GTK_BOX(box), nombre, TRUE, TRUE, 10);
    gtk_widget_show(nombre);

    gtk_table_attach(GTK_TABLE(table), box, 0, 2, 1, 2, GTK_FILL, GTK_FILL,
0, 0);
    gtk_widget_show(box);

    gtk_container_add(GTK_CONTAINER(window), table);


    gtk_widget_show(table);
    gtk_widget_show(window);

    gtk_main();
    return 0;
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]