Re: Modifying a button during runtime



>>>>> "J" == Jeff Shipman <shippy@cs.nmt.edu> writes:

 J> I've got a button that appears on my dialog right when it starts
 J> up. The thing is that it has a picture and some text inside of it
 J> that I would like to change depending on what the user does. How
 J> could I modify the contents of a button at runtime?

Hmm, maybe you can get what you want from gtk_pixmap_set and
gtk_label_set_text.  I've attached a program that shows how to change
the text in a button.  The pixmap is left as an exercise ;).

        /mailund


===File ~/tmp/qux.c=========================================
#include <gtk/gtk.h> 

static void 
set_label (GtkWidget *dummy, GtkWidget *label) 
{ 
  static gboolean foo = TRUE; 
  g_assert (GTK_IS_LABEL (label)); 
  if (foo) { 
    gtk_label_set_text (GTK_LABEL (label), "BAR"); 
    foo = FALSE; 
  } else { 
    gtk_label_set_text (GTK_LABEL (label), "FOO"); 
    foo = TRUE; 
  } 
}

int 
main (int argc, char *argv[]) 
{ 
  GtkWidget *win; 
  GtkWidget *box; 
  GtkWidget *label; 
  GtkWidget *button; 
  
  gtk_init (&argc, &argv); 
  
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
  box = gtk_vbox_new (TRUE, 5); 
  label = gtk_label_new ("FOO"); 
  button = gtk_button_new (); 

  gtk_container_add (GTK_CONTAINER (button), label); 
  gtk_box_pack_start_defaults (GTK_BOX (box), button); 
  gtk_container_add (GTK_CONTAINER (win), box); 
  
  gtk_signal_connect (GTK_OBJECT (button), "clicked", 
		      GTK_SIGNAL_FUNC (set_label), 
		      (gpointer)label); 

  gtk_widget_show_all (win); 
  
  gtk_main (); 
  
  return 0; 
}
============================================================



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