Tanya 183 : Contoh Penggunaan GtkComboBoxEntry

Tanya :
Bisa berikan contoh penggunaan GtkComboBoxEntry ?
Jawab :
Berikut kode yang diambil dari forum GTK+

[sourcecode language=”cpp”][/sourcecode]
#include <gtk/gtk.h>
void entry_activated_cb(GtkEntry *entry, gpointer user_data)
{
g_print("Text in entry is ‘%s’\n", gtk_entry_get_text(entry));
}
gint main(gint argc, gchar **argv)
{
GtkWidget *win;
GtkWidget *entry;
const gchar *items[] = {
"Item",
"Test",
"Hello",
"Hello again!",
NULL,
};
gint i;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(win, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
/* Memasukkan teks ke Combo Box */
entry = gtk_combo_box_entry_new_text();
for(i = 0; items[i] != NULL; i++)
gtk_combo_box_append_text(GTK_COMBO_BOX(entry), items[i]);
gtk_container_add(GTK_CONTAINER(win), entry);
gtk_widget_show(entry);
/* We can now access the GtkEntry portion by using GTK_BIN(entry)->child */
g_signal_connect(gtk_bin_get_child(GTK_BIN(entry)), "activate", G_CALLBACK(entry_activated_cb), NULL);
gtk_widget_show(win);
gtk_main();
return 0;
}
[/sourcecode]
Demikian. Semoga manfaat (rezaervani@gmail.com)

Be the first to comment

Leave a Reply

Your email address will not be published.


*