Menus¶
A menu widget provides a drop-down menu.
- menu(bind=myfunction, choices=choicelist)¶
- Parameters:
bind (function) – The function to be called when a menu selection is made.
choices (list) – The list of options (as strings) to appear on the menu.
selected (string) – The text of the currently selected menu option.
index (scalar) – The list position of the currently selected option.
disabled (boolean) – If True, menu is grayed out and does not respond.
delete() –
mymenu.delete()deletes the menu.
The following code creates a menu to change the color of an object:
pointer = arrow(pos=vec(-3,-3,0), axis=vec(6,6,0), color=color.white )
def changeattr(evt):
console.log(evt)
if evt.index < 1:
pass
elif evt.index is 1:
pointer.color=color.yellow
elif evt.index is 2:
pointer.color=color.magenta
elif evt.index is 3:
pointer.color=color.cyan
choicelist = ['Color', 'yellow', 'magenta', 'cyan']
menu( choices=choicelist, bind=changeattr )
Menu Event Attributes¶
The argument of the event handler function (‘evt’, in the code above) will have the following attributes (properties of the menu):
evt.indexevt.selectedevt.disabled
Additionally, any attributes you have created for the widget (for example, name or id), will be available as attributes of evt.
Accessibility Attributes¶
These attributes support ARIA (Accessible Rich Internet Applications), making widgets usable with screen readers and other assistive technology.
aria_label(string)A text label announced by screen readers when the widget receives focus. Use when there is no visible text that already identifies the widget:
myslider = slider(bind=setspeed, min=0, max=10, aria_label="Speed")
aria_labelledby(wtext)A wtext object whose text serves as the accessible label for this widget. Use when a visible
wtextalready describes the widget:speedlabel = wtext(text="Speed: ") myslider = slider(bind=setspeed, min=0, max=10, aria_labelledby=speedlabel)
aria_describedby(wtext)A wtext object that provides a longer accessible description of the widget, supplementing
aria_labeloraria_labelledby:hint = wtext(text="Drag left or right to set playback speed from 0 to 10") myslider = slider(bind=setspeed, min=0, max=10, aria_label="Speed", aria_describedby=hint)
See also