Panda3D Manual: DirectWaitBar

DirectWaitBars are similar to status bars; use them to indicate a slow process gradually completing (e.g. a loading screen). It has various options for both the background bar and the loading bar that fills up as the process progresses. You can call finish() to automatically fill up the bar, or use:

myWaitBar['value'] = number

to set the value (it ranges from 0 to 100 by default).

KeywordDefinitionValue
valueInitial value of the loading bar (from 0 to 100)Number
rangeThe maximum value of the loading barNumber
barColorThe color of the loading bar(R,G,B,A)
barTextureAn image to be display on the loading barimage filename or Texture object
barReliefThe relief appearance of the loading barSUNKEN or RAISED
barBorderWidthIf barRelief is SUNKEN, RAISED, GROOVE, or RIDGE, changes the size of the loading bar's bevel(Width,Height)
reliefThe relief appearance of the background barSUNKEN or RAISED

Example

import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from pandac.PandaModules 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 incBar(arg):
bar['value'] += arg
text = "Progress is:"+str(bar['value'])+'%'
textObject.setText(text)
 
# Create a frame
frame = DirectFrame(text = "main", scale = 0.001)
# Add button
bar = DirectWaitBar(text = "", value = 50, pos = (0,.4,.4))
 
# Create 4 buttons
button_1 = DirectButton(text="+1",scale=0.05,pos=(-.3,.6,0), command=incBar,extraArgs = [1])
button_10 = DirectButton(text="+10",scale=0.05,pos=(0,.6,0), command=incBar,extraArgs = [10])
button_m1 = DirectButton(text="-1",scale=0.05,pos=(0.3,.6,0), command=incBar,extraArgs = [-1])
button_m10 = DirectButton(text="-10",scale=0.05,pos=(0.6,.6,0), command=incBar,extraArgs = [-10])
 
# Run the tutorial
run()