Panda3D Manual: DirectCheckButton
  <<prev top next>>     

DirectCheckButtons are similar to buttons, except they represent a binary state that is toggled when it is clicked. Their usage is almost identical to regular buttons, except that the text area and box area can be modified separately.

KeywordDefinitionValue
text_scaleScale of the displayed text(sx,sz)
indicatorValueThe initial boolean state of the checkbox0 or 1
boxImageImage on the checkboxImage Path
boxImageColorColor of the image on the box(R,G,B,A)
boxImageScaleScale of the displayed imageNumber
boxPlacementPosition of the box relative to the text area'left','right'
boxReliefRelief appearance of the checkboxSUNKEN or RAISED
boxBorderSize of the border around the boxNumber
commandCommand the button performs when clicked
(0 or 1 is passed, depending on the state)
Function
extraArgsExtra arguments to the function specified in command[Extra Arguments]
commandButtonsWhich mouse button must be clicked to do the commandLMB, MMB, or RMB
rolloverSoundThe sound made when the cursor rolls over the buttonSound File Path
clickSoundThe sound made when the cursor clicks on the buttonSound File Path
pressEffectWhether or not the button sinks in when clicked<0 or 1>

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(status):
	if(status):
		bk_text = "Checkbox Selected"
	else:
		bk_text = "Checkbox Not Selected"
	textObject.setText(bk_text)

#add button
b = DirectCheckButton(text = "CheckButton" ,scale=.05,command=setText)

#run the tutorial
run()


A note on boxImage and other box* keywords

Just as DirectButton may be passed a 4-tuple of values to be used in the four button states, the box* keyword arguments may be supplied with multiple entries to denote the unchecked and checked state. To supply arguments to be used in the two states of the checkbox, construct a 3-tuple of values with a 'None' in the final entry, i.e. (unchecked, checked, None). For example, to set two different images for the unchecked and checked states:

boxImage = ("pathToDisabledImage.jpg","pathToEnabled.jpg",None)
  <<prev top next>>