trigger an event after last touch of widget

97 views
Skip to first unread message

Degenerate Tech

unread,
Nov 3, 2020, 6:33:01 AM11/3/20
to Kivy users support
how to call a method after last touch on widget ?
i want to disabled a widget after  5 second of  last touch .

Elliot Garbus

unread,
Nov 3, 2020, 12:03:36 PM11/3/20
to kivy-...@googlegroups.com

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.

 

Degenerate Tech

unread,
Nov 3, 2020, 12:36:22 PM11/3/20
to Kivy users support
yes ..it is so easy...why i am not thinking like you!!

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages