Show a label with a message...
- From: pks timing com
- To: jlalarcon tiggerfan com
- Cc: gtk-list gnome org
- Subject: Show a label with a message...
- Date: Sun, 15 Dec 2002 12:06:23 -0700
what's wrong ------------------------------------------------------------
> GtkWidget *message;
> GtkWidget *caja1;
> int main(int argc, char *argv[])
> {
> caja1 = gtk_hbox_new(TRUE, 0);
> message = gtk_label_new(" ");
> gtk_box_pack_start(GTK_BOX(caja1), message, TRUE, TRUE, 0);
> }
in the code above you are:
1) creating an hbox.
2) creating a label that is to display text " "
3) packing the label in the hbox.
gtk_label_new() instantiates a brand new label and
initializes it's text.
> void salute (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new("This is GTK programming.");
> }
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new(" ");
> }
in both of these functions you *instantiating* yet another
label, which is never packed anywhere or shown. This is
not what you want to do ...
what you're likely trying to get done -----------------------------------
is to change the text of the label you have created in main() instead
of creating a new one:
> void salute (GtkWidget *widget, gpointer data)
> {
> gtk_label_set_text(GTK_LABEL(message), "This is GTK programming.");
> }
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> gtk_label_set_text(GTK_LABEL(message), "This is GTK programming.");
> }
or to show and and hide the label all together:
> int main(int argc, char *argv[])
> {
> caja1 = gtk_hbox_new(TRUE, 0);
> message = gtk_label_new("This is GTK programming.");
> gtk_box_pack_start(GTK_BOX(caja1), message, TRUE, TRUE, 0);
> }
> void salute (GtkWidget *widget, gpointer data)
> {
> gtk_widget_show(message);
> }
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> gtk_widget_hide(message);
> }
something for the heck of it --------------------------------------------
change your exising implementations of:
> void salute (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new("This is GTK programming.");
> }
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new(" ");
> }
to
> void salute (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new("new SALUTE label.");
> gtk_box_pack_start(GTK_BOX(caja1), message, TRUE, TRUE, 0);
> gtk_widget_show(message);
> }
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> message = gtk_label_new("new HIDE label.");
> gtk_box_pack_start(GTK_BOX(caja1), message, TRUE, TRUE, 0);
> gtk_widget_show(message);
> }
and you'll have a better understanding of what you
were doing to begin with.
Note that overwriting the *message pointer with the newly
allocated widgets probably isn't good practice.
The only way you'll get a reference to the labels you
have instantiated before the most recent one (to change
text, show/hide, or even deallocate them) is by means of
access functions on the container you stuffed them into
(such as gtk_container_children()).
and because I'm feeling fat and sassy --------------------------------
> my idea is that i am doing a bad use of gtk_label_new() or
> gtk_signal_connect() functions, but......
if you're worried about the signal handlers not being called
you can add something as simple as printf() to the signal
handler ...
> void salute_hide (GtkWidget *widget, gpointer data)
> {
> printf("Show button was pressed\n");
> }
and check output on the terminal window you started
your application from.
now go and read some more examples - you'll figure it out ;)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]