The DirectOptionMenu class models a popup menu with an arbitrary number of items. It is composed of the menu bar, the popup marker, and the popup menu itself. The popup menu appears when the menu is clicked on and disappears when the user clicks again; if the click was inside the popup, the selection changes. By default, the text on the menu changes to whatever item is currently selected. The attributes that affect the appearance of the menu bar don’t apply to the popup. Make sure to specify the items option or it may crash.

Keyword

Definition

Value

textMayChange

Whether the text on the menu changes with the selection

0 or 1

initialitem

The index of the item that appears next to the cursor when the popup appears

Number

items

List of items in the popup menu

[Strings]

command

Function called when an item is selected (the item is passed in as a parameter)

Function

commandButtons

Which mouse button must be clicked to open the popup

LMB, MMB, or RMB

extraArgs

Extra arguments to the function specified in command

[Extra Arguments]

highlightColor

Color of highlighted text

(R,G,B,A)

highlightScale

Scale of highlighted text

(Width,Height)

rolloverSound

The sound made when the cursor rolls over the button

Sound File Path

clickSound

The sound made when the cursor clicks on the button

Sound File Path

popupMarkerBorder

Use width to change the size of the border around the popup marker

(Width,Height)

popupMarker_image

Set the state images of the popupMarker

(see directButton: image)

popupMarker_scale

Set the scale of the popupMarker

scale=x or scale=(x,y,z)

popupMarker_pos

Set the poition of the popupMarker relative to the parent optionMenu

pos=(x,y,z)

popupMarker_relief

Set the relief value of the popupMarker, the depth of the beveled edge

relief=x (for int value) or relief=None (for no relief)

## Example¶

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *

textObject = OnscreenText(text=bk_text, pos=(0.85, 0.85), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)

output = ""
textObject = OnscreenText(text=output, pos=(0.95, -0.95), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)

# Callback function to set  text
def itemSel(arg):
output = "Item Selected is: " + arg
textObject.setText(output)

# Create a frame
items=["item1", "item2", "item3"], initialitem=2,
highlightColor=(0.65, 0.65, 0.65, 1))

# Run the tutorial
base.run()


This is a simple demonstration of the DirectOptionMenu.

## Dynamic Updating of a Menu¶

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *

textObject = OnscreenText(text=bk_text, pos=(0.85, 0.85), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)

output = ""
textObject = OnscreenText(text=output, pos=(0.95, -0.95), scale=0.07,
fg=(1, 0.5, 0.5, 1), align=TextNode.ACenter,
mayChange=1)

# Callback function to set text
def itemSel(arg):
# No need to add an element
output = "Item Selected is: " + arg
textObject.setText(output)
else:
# Set the status message
output = "Item Added is: " + new_item
textObject.setText(output)

# Create a frame