user20546541
user20546541

Reputation: 1

Is there a way to disable kivy button with an external condition?

I'm trying to build a program that takes a physical input and do some stuff(obj and motors) and while those two function are executing I need to disable a button. I tried something like this but nothing happens. Is there a way to enable/disable a button with a python function? Thanks in advance.

async def action():
    await MainMenu.disable()
    await obj()
    motors()
    print('action is finished, starting loop agian')
    await MainMenu.enable()
class MainMenu(Screen):
    running = BooleanProperty(False)
    
    async def disable():
        running = BooleanProperty(True)
        return running
    
    async def enable():
        running  = BooleanProperty(False)
        return running 
    pass

kv file

<MainMenu>:
    Button:
        text: 'button that needs to be disabled'
        disabled: root.running

Upvotes: 0

Views: 204

Answers (1)

John Anderson
John Anderson

Reputation: 39012

You are not assigning values to the running Property correctly. In your methods, just do something like:

self.running = True

or

self.running = False

This code should work:

class MainMenu(Screen):
    running = BooleanProperty(False)

    def disable(self):
        self.running = True

    def enable(self):
        self.running = False

Upvotes: 1

Related Questions