Hi,
I use DirectButton in my application. I saw in the doc there is a ‘disabled’ state, but I didn’t find how to change the button’s state.
Thanks.
Hi,
I use DirectButton in my application. I saw in the doc there is a ‘disabled’ state, but I didn’t find how to change the button’s state.
Thanks.
hmm… I’m not sure, but you can try either myButton.disableEdit() or myButton.setState…
I already tried these 2 funcs and it didn’t do anything.
The problem with setState is that it doesn’t take any arguments to specify the wanted state, so it’s a little strange.
DirectButton is implemented in Python, which doesn’t have enable/disable state toggle. But it’s C++ class, PGButton, which inherits from PGItem does have this ability.
DB.node().setActive(0)
Actually, the DirectButton class does support the enabled state toggle. It’s set via the ‘state’ member:
button['state'] = DGG.DISABLED
button['state'] = DGG.NORMAL
David
Thank you, it works.
Somehow I can’t seem to get this to work properly, when I use it like that, changing the word button to my button, or anyword all give errors, and about DGG it says it’s not defined. Could you make a short example please on how to use it when I’d name my button 'start’for example?
Many thanks in advance.
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.gui.DirectGui import *
class ButtonApplication(DirectObject):
def __init__(self):
self.b = DirectButton(text = ("Normal",
"Click", "Over", "Disabled"))
self.accept("f1", self.enable)
self.accept("f2", self.disable)
def enable(self):
self.b['state'] = DGG.NORMAL
def disable(self):
self.b['state'] = DGG.DISABLED
ba = ButtonApplication()
run()
With F1 and F2 you may enable/disable the button. Hope that helps.
Azraiyl
Why so complicated? state=1 enables the button, state=0 disables it. I used it a lot for my menu stuff…