Set fixed text in DirectOptionMenu

i am facing the following issue with DirectOptionMenu
i use DirectOptionMenu(text=‘options’, scale=0.05, items=[‘item1’, ‘item2’])
i need for the menu text to be always ‘options’ and when i click to give me the list of items.
instead the ‘options’ never appears and it is always set to one of item1, item2.
if i use textMayChange=0 again the text is always constant to item1.
i dont understand what the text=‘something’ is used for if not to provide the name of the menu itself.

I think that the idea is that it shows, not the name of the menu, but the currently-selected item.

However, I do agree that it would be useful to be able to apply static text to such a menu! And indeed, I have a pull request open on GitHub that implements such a feature (see here), so this may well be included in a later version of the engine. :slight_smile:

1 Like

yap, i thought so
i thought that there might be some undocumented way to do this,
fore the time being i just add an OnScreenText right next to each menu

1 Like

Fair enough, and it’s my pleasure! :slight_smile:

As I’ve needed this too and found an easy workaround with the current DirectOptionMenu, I’ll share a little snippet here:

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectOptionMenu import DirectOptionMenu

App = ShowBase()

def selectCommand(selection):
    # reset the text to "Options"
    menu["text"] = "Options"

menu = DirectOptionMenu(
    items=["item1", "item2"],
    frameSize=(0.05, 3.6, -0.34, 0.75),

# Make sure the initial text is "Options"
menu["text"] = "Options"

It will reset the text every time the user selects a new option. Dependent on the size of the text you may need to correctly set the frameSize manually though as this is calculated from the initial items given to the option menu.

This way you still can use the get() method to get the selected option or handle the users’ selection right in the selectCommand method.


yap that worked!