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

Re: [gnome-love] Modifying widget's w/ libglade



On Fri, 2001-09-21 at 10:24, Cameron Matheson wrote:
> Hey,
> 
> I wrote this little program (I'm trying to learn how to use libglade),
> and what I'm trying to do, is make the text of a button change when the
> button is clicked.  Unfortunately, I don't know how to access the
> button's label in my signal-handler, could anyone tell me how that works
> (maybe w/ example code?)

I've attached a program that changes the label on a button when you
click it. Not libglade stuff, but you can probably figure that part out
yourself.

The idea is the following: GtkButton is a GtkBin, and such a guy
contains a 'child', which in the case of a button, if the button was
created with new_with_label anyway, is a GtkLabel. So to get the label
you write GTK_LABLEL (GTK_BIN (button)->child).

	/mailund

-- 
A computer lets you make more mistakes faster than any invention in
human history - with the possible exceptions of handguns and tequila.

Mitch Ratcliffe, "Technology Review" (1992)
#include <gtk/gtk.h>

static void
button_clicked (GtkButton *button)
{
  GtkLabel *label;
  static gboolean toggle = FALSE;

  label = GTK_LABEL (GTK_BIN (button)->child);

  if (toggle)
    {
      gtk_label_set_text (label, "pot");
    }
  else
    {
      gtk_label_set_text (label, "crack");
    }
  toggle = !toggle;
}


int
main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *button;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  button = gtk_button_new_with_label ("smack");
  gtk_container_add (GTK_CONTAINER (win), button);

  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (button_clicked),
		      NULL);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;
}


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