Re: Newbie prob with functions...
- From: JParker coinstar com
- To: "Nicolas Raitman" <new_world radar com ar>
- Cc: "gtk app" <gtk-app-devel-list gnome org>, gtk-app-devel-list-admin gnome org
- Subject: Re: Newbie prob with functions...
- Date: Thu, 16 Nov 2000 16:29:38 -0800
G'Day !
Lets see now ... You want to get some text from a gtk_entry and put it into a
label. Well here is a function to print a label form a string passed to it
/******************************************************************************
* PrintDebugInfo ( )
*
* Prints debug information to a label on bottom of GTK+ window
*****************************************************************************/
static gint
PrintDebugInfo (gchar *szMessage)
{
gchar buffer[50];
sprintf (buffer, "%s", szMessage);
gtk_label_set (GTK_LABEL (debug_label), buffer);
return TRUE;
}
Of course, some where in main( ) or preferably a CreateMainWindow( ) function I
created the label (it looks like you did that correctly), just make sure it is
in scope (ie availble to the PrintFunction above. In my example I used a global
variable. Someone intellegent would of passed the function the label name so
they could use the same function for multiple labels ;-)
Now to get the string from the gtk_entry ( ) ... This snippet is from the
tutorial:
"The contents of the Entry can be retrieved by using a call to the following
function. This is useful in the callback functions described below.
gchar *gtk_entry_get_text( GtkEntry *entry );
The value returned by this function is used internally, and must not be freed
using either free() or g_free()"
So what you need to do is place the above line in the button callback and then
call the print label function with the returned string.
Hope this help.
cheers,
Jim Parker
Sailboat racing is not a matter of life and death .... It is far more important
than that !!!
"Nicolas Raitman"
<new_world radar com ar> To: "gtk app" <gtk-app-devel-list gnome org>
Sent by: cc:
gtk-app-devel-list-admin Subject: Newbie prob with functions...
@gnome.org
11/16/00 04:02 PM
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;
}
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]