Can the DirectSlider in DirectGUI have its value changed programatically?


Ex. pressing the space bar causes the thumb of the slider to move to the right. The “value” parameter seems to only affect the initial position.


Could you share an idea for what you need it. You just asked in the previous topic how to turn off the mouse effect. You can use regular CardMaker or geometry. And manage it as you like.


Of course! I mentioned turning off mouse effect just as an afterthought, it’s not too important for my purposes but I thought I’d ask. What I’m getting at with my “flightcontrols” class from the other topic is an experiment on setting up a hypothetical avian character controller without going through the hassle of making assets and setting up physics and animations first, hence why I’m using DirectGUI to visualize. XD

I’m trying to use a direct slider to show how far the wings on say, a bird, are open. The slider starts at halfway, and by holding space to turn off normal left/right movement, you can use the wasd keys to open or close the wings (thus increasing or decreasing falling speed when physics comes into play.)

In short, it doesn’t have to be a slider, but that’s the kind of visual graphic I’m going for, so long as I can get keys to affect it. Can you explain more about CardMaker and geometry?


As far as I know slider['value']=some_new_value is the right thing to use if you want to change the position and value of a DirectSlider after creating it.


That works! I should’ve thought of that given what I learned on the other topic. Thanks!


To tell a long time, so I will show. :slightly_smiling_face:

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import DirectCheckButton, DirectSlider
from panda3d.core import CardMaker, TextureStage

class FlightControls(ShowBase):

    def __init__(self):


        cm = CardMaker("create_mesh")
        cm.setFrame(-1/base.getAspectRatio(), 1/base.getAspectRatio(), -1, 1)
        self.leftB = render2d.attachNewNode(cm.generate())
        tex_fon = loader.loadTexture('left.png')
        ts = TextureStage('ts')
        self.leftB.setTexture(ts, tex_fon)
        self.leftB.setPos(-0.3, 0, 0.5)
        self.rightB = render2d.attachNewNode(cm.generate())
        tex_fon = loader.loadTexture('right.png')
        ts = TextureStage('ts')
        self.rightB.setTexture(ts, tex_fon)
        self.rightB.setPos(0.3, 0, 0.5)

        del cm, tex_fon, ts

        self.key_a = self.accept('a', self.setValue, [self.leftB, True, 1])
        self.key_a = self.accept('a-up', self.setValue, [self.leftB, False, None])
        self.key_d = self.accept('d', self.setValue, [self.rightB, True, -1])
        self.key_d = self.accept('d-up', self.setValue, [self.rightB, False, None])

    def setValue(self, key, status, vec):
            if status:
                print ("Move X "+str(vec))
                print ("X "+str(vec))

app = FlightControls()

left.png left right.png right


Ah, thank you! Definitely going to learn this :slight_smile: