Panda3D Manual: DirectRadioButton

This feature is only available in Panda3D versions 1.5.3 and higher

DirectRadioButtons are similar to check buttons, except only one button is selected 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 radiobutton0 or 1
variableThe variable whose value will be set by radiobutton. Since we can not use call by reference for int or string variables in python, I used a list insteads.define a list and pass it
valueThe value to be set to the variable. Since we are using a list, we can define multiple values. But the length of value list must be same as length of variable list.a list of values
othersThe list of radio button instances sharing same variable. This must be set by using setOthers() after all radiobutton is created.a list of radioButton instances
boxImageBG Image of the radio buttonImage Path
boxImageColorColor of the BG image(R,G,B,A)
boxImageScaleScale of the BG imageNumber
boxGeomFG Image on the radio buttonImage Path
boxGeomColorColor of the FG image(R,G,B,A)
boxGeomScaleScale of the FG imageNumber
boxPlacementPosition of the box relative to the text area'left','right', 'above', 'below', 'center'
boxBorderSize of the border around the boxNumber
commandCommand the button performs when clicked (In version 1.6 and higher, no parameter is passed unless extraArgs are defined. Before, a single argument was passed by default.)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 *
from pandac.PandaModules import *
 
v = [0]
# 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=None):
bk_text = "CurrentValue : %s"%v
textObject.setText(bk_text)
 
# Add button
buttons = [
DirectRadioButton(text = 'RadioButton0', variable=v, value=[0], scale=0.05, pos=(-0.4,0,0), command=setText),
DirectRadioButton(text = 'RadioButton1', variable=v, value=[1], scale=0.05, pos=(0,0,0), command=setText),
DirectRadioButton(text = 'RadioButton2', variable=v, value=[2], scale=0.05, pos=(0.4,0,0), command=setText)
]
 
for button in buttons:
button.setOthers(buttons)
 
# Run the tutorial
run()