1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <stdlib.h>
#include <gtk/gtk.h>
/* Compilation:
* gcc $(pkg-config --libs --cflags gtk+-2.0) test.c -o test
*/
gint ButtonPressed(GtkWidget* widget, gpointer data)
{
g_print("You pressed the button.\n");
return FALSE;
}
void combo_selected(GtkWidget *widget, gpointer data)
{
gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget));
if (text == "Pomme")
{
//J'aimerais qu'il m'affiche autre chose que pour la sélection "pomme" qui deviendrait par exemple "pomme verte"
text = "pomme verte";
}
gtk_label_set_text(GTK_LABEL(data), text);
g_free(text);
}
int main(int argc, char *argv[])
{
/* Variables */
GtkWidget* pWindow;
GtkWidget* label;
GtkWidget* selection;
//GtkWidget* button;
GtkWidget* fixed;
GtkWidget* combo;
gtk_init(&argc, &argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); //Définition de la fenêtre
gtk_window_set_title(GTK_WINDOW(pWindow), "test"); //Titre de la fenêtre
gtk_window_set_default_size(GTK_WINDOW(pWindow), 400, 130); //Taille de la fenêtre
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(pWindow), fixed);
label = gtk_label_new(NULL); //Texte du label
gtk_label_set_markup(GTK_LABEL (label), "<u>Liste de fruits:</u>");
gtk_fixed_put(GTK_FIXED(fixed), label, 10, 10);
//button = gtk_button_new_with_label("Quitter");
//gtk_fixed_put(GTK_FIXED(fixed), button, 50, 50);
//gtk_widget_set_size_request(button, 80, 35);
combo = gtk_combo_box_new_text();
gtk_fixed_put(GTK_FIXED(fixed), combo, 10, 35);
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Fraise");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Poire");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Pomme");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Banane");
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Kiwi");
gtk_widget_set_size_request(combo, 150, 30);
selection = gtk_label_new(NULL);
gtk_fixed_put(GTK_FIXED(fixed), selection, 165, 42);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
//g_signal_connect(G_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(ButtonPressed), NULL);
g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(combo_selected), selection);
gtk_widget_show_all(pWindow); //On affiche la fenêtre et ce qu'elle contient
gtk_main();
return EXIT_SUCCESS;
} |
Partager