change picture and text on button click
- From: rupert <rupertt gmail com>
- To: gtk-app-devel-list gnome org
- Subject: change picture and text on button click
- Date: Sat, 4 Mar 2006 21:09:26 +0100
How can i change a picture on the fly when I klick a button(or select a line
in a treeview)?
As i understood i can get the actuall picture with g_object_get and set a
new one with g_object _set,
so i do a gdk_pixbuf_new_from_file and put that into pixbuf, but I only get
some error in the bash:
(spielkram:7144): GLib-GObject-WARNING **: IA__g_object_get_valist: object
class `GtkButton' has no property named `pixbuf'
Also, please point to some forums on the GTK Website, its hard to find some
User Guided guides on google or elsewhere.
/* -*-coding: utf-8;-*- */
#include <gtk/gtk.h>
#include <stdio.h>
gint delete_event(GtkWidget *widget, GdkEvent event, gpointer daten){
return FALSE;
}
void ende(GtkWidget *widget, gpointer daten){
gtk_main_quit();
}
void hallo(void){
g_print("ja\n");
}
void bild_aktualisieren(GtkImage *bild){
static GdkPixbuf *start_shot = NULL;
GdkPixbuf *pixbuf;
g_object_get(bild, "pixbuf", &pixbuf, NULL);
pixbuf = gdk_pixbuf_new_from_file("2.png", NULL);
g_object_set(bild, "pixbuf", NULL);
g_object_unref(pixbuf);
}
int main(int argc, char **argv)
{
GtkWindow *fenster;
GtkLabel *titel;
GtkImage *bild;
GtkWidget *fixed;
GtkButton *knopf;
gtk_init(&argc, &argv);
fenster = g_object_new(GTK_TYPE_WINDOW, "title", "Anzeigeelemente",
"border-width", 12, NULL);
g_signal_connect(fenster, "delete-event", G_CALLBACK(delete_event),
NULL);
g_signal_connect(fenster, "destroy", G_CALLBACK(ende), NULL);
fixed = gtk_fixed_new ();
gtk_container_add (GTK_CONTAINER (fenster), fixed);
gtk_widget_show (fixed);
titel = g_object_new(GTK_TYPE_LABEL, "label", "Hallo", NULL);
bild = g_object_new(GTK_TYPE_IMAGE, "file", "1.gif", NULL);
knopf = g_object_new(GTK_TYPE_BUTTON, "label", "fester", NULL);
g_signal_connect(knopf, "clicked", G_CALLBACK(hallo), NULL);
g_signal_connect(knopf, "clicked", G_CALLBACK(bild_aktualisieren),
NULL);
gtk_fixed_put(GTK_FIXED(fixed), bild, 21, 14);
gtk_fixed_put(GTK_FIXED(fixed), titel, 1, 2);
gtk_fixed_put(GTK_FIXED(fixed), knopf, 32, 54);
gtk_widget_show_all(GTK_WIDGET(fenster));
gtk_main();
return (0);
}
thx
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]