Menus¶

_images/menu.png

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.index

  • evt.selected

  • evt.disabled

Additionally, any attributes you have created for the widget (for example, name or id), will be available as attributes of evt.

See also

Event Handlers; Processing Events; Polling; Widget Position

VPython

Navigation

Contents:

  • 3D Objects
  • Animations
  • Canvases
  • Camera and Lighting
  • Color/Opacity/Glow
  • Design New Objects
  • Files/Libraries
  • Graphs
  • Math Functions
  • Object Attachments
  • Rotation
  • Text output
  • Textures
  • User Input
    • Buttons
    • Checkboxes
    • Key input
    • Menus
    • Mouse input
    • Radio buttons
    • Text input
    • Sliders
    • Widget Position
    • Processing Events
  • VPython/WebVpython
  • VPython license
  • Additional Resources

Related Topics

  • Documentation overview
    • User Input
      • Previous: Key Input
      • Next: Mouse Input

Quick search

©2023, Ruth Chabay and Bruce Sherwood. | Powered by Sphinx 5.0.2 & Alabaster 0.7.12 | Page source