When the button is touched schedule an event (Clock.schedule_once()) that will disable the button in 5 seconds. If the button is pressed cancel the scheduled event.
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.button import Button
kv = """
BoxLayout:
orientation: 'vertical'
TimeButton:
id: tb
text: 'Press to disable 5 seconds after last touch'
on_release: self.five_second_disable()
Button:
size_hint_y: None
height: 48
text: 'Reset'
on_release: tb.disabled = False
"""
class TimeButton(Button):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.schedule = None
def five_second_disable(self):
if self.schedule:
self.schedule.cancel()
self.schedule = Clock.schedule_once(self._disable, 5)
def _disable(self, dt):
self.disabled = True
self.schedule = None
class TimeButtonApp(App):
def build(self):
return Builder.load_string(kv)
TimeButtonApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/31c524f7-add0-4019-9a2b-30293d59ba31o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.