Getting value from an option menu
- From: Dean Schumacher <dean schumacher usa alcatel com>
- To: gtk-app-devel-list gnome org
- Subject: Getting value from an option menu
- Date: Thu, 01 Mar 2001 17:27:11 -0600
Hello. I'm just starting to learn GTK+ programming and am having
trouble figuring out how to get the value the user has selected
on an option menu.
Looking in the online GTK+ Reference Manual, there doesn't seem
to be any function to get the value.
I've looked at some examples in the user group archives and
have come up with the following code which tries to get the
label from the option menu. I don't know how far off this is,
but it fails because the child of the menu item is NULL, not
a label.
GtkWidget *option_menu;
GtkWidget *menu;
GtkWidget *menu_item;
GtkWidget *label;
gchar *value;
/* Use Libglade call to get the GtkWidget */
option_menu = glade_xml_get_widget(xml, "optionmenu1");
menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
menu_item = gtk_menu_get_active(GTK_MENU(menu));
assert(GTK_IS_MENU_ITEM(menu_item));
assert(menu_item != NULL);
assert(GTK_BIN(menu_item)->child != NULL); /* ASSERTION FAILS */
assert(GTK_IS_LABEL(GTK_LABEL(GTK_BIN(menu_item)->child)));
label = GTK_WIDGET(GTK_BIN(menu_item)->child);
value = GTK_LABEL(label)->label;
Also, I'm thinking, surely there's an easier way of doing
this. For a GtkEntry object, it just takes a single call
to gtk_entry_get_text. Is there not something similar to get
the value from an option menu? I can't find it in any
documentation.
I'm using the online GTK+ Reference Manual (which has no examples)
and the "Beginning GTK+/GNOME Programming" book by Peter Wright as
my reference. Any other suggestions?
Thank you very much for any help.
Regards,
--
Dean Schumacher Email: dean schumacher usa alcatel com
Software Engineering Tools Phone: 972.519.3252
Alcatel USA
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]