Panda3D Manual: DirectEntry
  <<prev top next>>     

The DirectEntry creates a field that accepts text entered by the user. It provides a blinking cursor and support for backspace and the arrow keys. It can accept either a single line of text, with a fixed width limit (it doesn't scroll), or it can accept multiple word-wrapped lines.

KeywordDefinitionValue
initialTextInitial text to load in the fieldString
entryFontFont to use for text entryFont object
widthWidth of field in screen unitsNumber
numLinesNumber of lines in the fieldInteger
cursorKeysTrue to enable the use of cursor keys (arrow keys)0 or 1
obscuredTrue to hide passwords, etc.0 or 1
commandFunction to call when enter is pressed
(the text in the field is passed to the function)
Function
extraArgsExtra arguments to the function specified in command[Extra Arguments]
rolloverSoundThe sound made when the cursor rolls over the fieldSound File Path
clickSoundThe sound made when the cursor inside the fieldSound File Path
focusWhether or not the field begins with focus (focusInCommand is called if true)0 or 1
backgroundFocusIf true, field begins with focus but with hidden cursor, and focusInCommand is not called0 or 1
focusInCommandFunction called when the field gains focusFunction
focusInExtraArgsExtra arguments to the function specified in focusInCommand[Extra Arguments]
focusOutCommandFunction called when the field loses focusFunction
focusOutExtraArgsExtra arguments to the function specified in focusOutCommand[Extra Arguments]

Example

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

#add some text
bk_text = "This is my Demo"
textObject = OnscreenText(text = bk_text, 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 setText(textEntered):
	textObject.setText(textEntered)

#clear the text
def clearText():
	b.enterText('')

#add button
b = DirectEntry(text = "" ,scale=.05,command=setText,
initialText="Type Something", numLines = 2,focus=1,focusInCommand=clearText)

#run the tutorial
run()

This example implements a text entry widget typically seen in web pages.

  <<prev top next>>