| FAQ Index - Search - Recent Changes - Everything - Add entry |
16.2. Let's say I accept it as it is. How do I implement one using pygtk?
David Pinson has sent in an example to keep us all sane:
def on_optionmenu_activate(widget, data):
print data # print the data for the
# current selection
options = ["cat", "dog", "mouse"] # our options
menu = gtk.Menu() # create a menu
for str in options: # fill our menu with the options
menu_item = gtk.MenuItem(str)
menu_item.connect("activate", # attach "str" to widget
on_optionmenu_activate, str)
menu_item.show() # don't forget this here
menu.append(menu_item)
option_menu = gtk.OptionMenu() # create the optionmenu
option_menu.set_menu(menu) # add the menu into the optionmenu
(Note that Kiwi also includes a new API for the OptionMenu that makes it much easier to manipulate: it does signal connection automatically, fills the menu and attaches objects to the items. Check it out)
