tags:

views:

359

answers:

1

Sorry everyone my english is poor , i'm still learning. Let me say this as plainly as I can

this is my question. if i create a application , like this.

--------------------------------
image 1|image 2|image 3| (button)
--------------------------------

i wanna if i clicked button,the application image will be change

----------------------------------
image A|image B|image C| (button)
----------------------------------

please help me ,send me some tips thank you!

there is some code

#include <gtk/gtk.h>
static GtkWidget *image1,*image2,*image3;
static GtkWidget *window;
static GtkWidget *hbox;
static GtkWidget *button;

static void buttonefresh(GtkWidget *button ,gpointer data)
{

  image1 = gtk_image_new_from_stock(GTK_STOCK_QUIT,GTK_ICON_SIZE_MENU);
  image2 = gtk_image_new_from_stock(GTK_STOCK_QUIT,GTK_ICON_SIZE_MENU);
  image3 = gtk_image_new_from_stock(GTK_STOCK_QUIT,GTK_ICON_SIZE_MENU);

  gtk_box_pack_start (GTK_BOX (hbox), image1, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), image2, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), image3, FALSE, TRUE, 0);
  gtk_widget_show (window);

 }

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

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Image Refresh");

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);
  hbox = gtk_hbox_new (FALSE, 5);
  button=gtk_button_new_with_label("Refresh");

  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (buttonefresh), NULL);
  g_signal_connect (G_OBJECT (button), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  image1 = gtk_image_new_from_stock(GTK_STOCK_OPEN,GTK_ICON_SIZE_MENU);
  image2 = gtk_image_new_from_stock(GTK_STOCK_OPEN,GTK_ICON_SIZE_MENU);
  image3 = gtk_image_new_from_stock(GTK_STOCK_OPEN,GTK_ICON_SIZE_MENU);

  gtk_box_pack_start (GTK_BOX (hbox), image1, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), image2, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), image3, FALSE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (window), hbox);
  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}
+1  A: 

In your callback for the click, just call any of GtkImage's methods that change the image, for instance gtk_image_set_from_image().

You might need to pass along enough data using the gpointer user_data argument so the callback knows which GtkImage instance to change, and what to change it to.

You should not need to re-create the GtkImage widgets, just change the image displayed.

unwind