Vizard 8 » Tutorials & Examples » 3D models » Text nodes » Tutorial: Changing the message
8.0

Tutorial: Changing the message

To change the value of the text use the <node3D:text3D>.message command. Add the following code to change the 3D text message:

text3D.message('Art Gallery')

Now, change the 2D text message and position it just above the painting of Starry Night:

text2D.message('Starry Night')
text2D.setPosition([0, 3, 9.8])
text2D.setScale([0.4,0.4,0.4])

Finally, we'll add a function that updates the screen text when the mouse cursor is over a painting. Using <window>.pick, we're returned a sub-object from the scene (e.g. bench, door, painting, wall) based on the cursor position. If the sub-object is a painting, it's name is displayed:

textScreen.message('')
def updateScreenText():
    object = viz.MainWindow.pick(info=True)
    if object.valid:
        name = object.name
        if name.startswith('painting_'):
            name = name.replace('painting_','')
            textScreen.message(name)
        else:
            textScreen.message('')

vizact.ontimer(0.1,updateScreenText)

Run the script and move the mouse cursor over the various paintings.

Setting up a text world

Creating text

Changing the font

Changing the message