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

Re: Re : Loading Images



Here is a small example piece of code, which display a gif image in an 
event box :


#include <gtk/gtk.h>


/* when invoked (via signal delete_event), terminates the application.
 */
gint close_application( GtkWidget *widget,
                        GdkEvent  *event,
                        gpointer   data )
{
    gtk_main_quit ();
    return FALSE;
}

  static gboolean
  button_press_callback (GtkWidget      *event_box,
                         GdkEventButton *event,
                         gpointer        data)
  {
    g_print ("Event box clicked at coordinates %f,%f\n",
             event->x, event->y);

    /* Returning TRUE means we handled the event, so the signal
     * emission should be stopped (don't call any further
     * callbacks that may be connected). Return FALSE
     * to continue invoking callbacks.
     */
    return TRUE;
  }

int main( int   argc,
          char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
    GtkWidget *image;
    GtkWidget *event_box;

    /* create the main window, and attach delete_event signal to terminating
       the application */
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (window), "delete_event",
                      G_CALLBACK (close_application), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    gtk_widget_show (window);
    image = gtk_image_new_from_file ("image.gif");

    event_box = gtk_event_box_new();

    gtk_container_add (GTK_CONTAINER (event_box), image);
    gtk_container_add (GTK_CONTAINER (window), event_box);
    gtk_widget_show (event_box);
    gtk_widget_show (image);


    g_signal_connect (G_OBJECT (event_box),
                      "button_press_event",
                      G_CALLBACK (button_press_callback),
                      image);

    gtk_main ();

    return 0;
}


Hope it can help you.
Hugues.


RTD wrote:

>Hi Everybody,
>
>          I have a problem loading an gif image to the label
>or eventbox.
>          If anyone knows how to add the images to the label/
>eventboxes please let me know the solution.
>
>
>
>
>=====
>Ravindra  T.  Dolas,
>Pune-INDIA
>
>__________________________________
>Do you Yahoo!?
>The New Yahoo! Search - Faster. Easier. Bingo.
>http://search.yahoo.com
>_______________________________________________
>gtk-list mailing list
>gtk-list@gnome.org
>http://mail.gnome.org/mailman/listinfo/gtk-list
>
>  
>






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