[python]代码库
from panda3d.core import TextNode
from direct.gui.DirectGui import *
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Create a button
self.button = DirectButton(text=("Click me!"),
scale=.1,
command=self.onButtonClicked)
self.button.reparentTo(self.aspect2d)
self.button.setPos(0, 0, -.5)
# Create a text box
self.textNode = TextNode("text")
self.textNode.setText("Hello, world!")
self.textNodePath = aspect2d.attachNewNode(self.textNode)
self.textNodePath.setScale(0.07)
self.textNodePath.setPos(0, 0, 0.1)
def onButtonClicked(self):
self.textNode.setText("Button clicked!")