DirectButton question

I want to change the font color of a DirectButton whenever it is rolled over.

According to the manual, the correct code should be something like this:

b = DirectButton(text_fg=((1,0,0,1), (1,1,0,1), (1,0,1,1), (0,1,1,1)))

However, the program crashes with the following error:

textNode.setTextColor(fg[0], fg[1], fg[2], fg[3])
TypeError: a float is required

The same code works fine when changing other parameters, like the text, etc.
[/code]

The 4-tuple syntax is used when setting a toplevel component value, like “text”. When you want to set a secondary component value–that is, an individual property of one of the toplevel components, like text_fg–you set each value individually, like this:

b = DirectButton(text = 'button', scale = 0.1, text0_fg=(1,0,0,1), text1_fg=(1,1,0,1), text2_fg=(1,0,1,1), text3_fg=(0,1,1,1))

David

Thanks! Worked perfectly.

I’m trying to make a GUI that simulates nested DirectOptionMenus using DirectButtons. Is there any way to have the command parameter in a DirectButton pass multiple parameters to a handler function?

You mean with the command and extraArgs keywords?

Yup, that did the trick.

Is there documentation anywhere describing the getRelativePosition() and project() functions?

Do you mean NodePath.getRelativePoint(), and Lens.project()? Both of those are described in the API reference.

David