'kivy on_touch_up() fires more than one time?
I wonder, is there a way in kivy, where the method on_touch_up() fires continuously, when true? The output would look like this:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse, Line
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
with self.canvas:
Color(1, 1, 0)
touch.ud['line'] = Line(points=(touch.x, touch.y))
print(touch.spos, "Down")
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
print(touch.spos,"Move")
def on_touch_up(self, touch):
print(touch.spos,"Up")
###
#while on_touch_up():
#print(touch.spos,"Up")
###
class MyPaintApp(App):
def build(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
It prints:
((0.2175, 0.7716666666666667), 'Down')
((0.2175, 0.7716666666666667), 'Move')
((0.2175, 0.685), 'Move')
((0.2175, 0.5516666666666667), 'Move')
((0.2175, 0.4633333333333334), 'Move')
((0.2175, 0.44666666666666666), 'Move')
((0.2175, 0.44666666666666666), 'Up')
((0.2175, 0.43500000000000005), 'Down')
((0.23, 0.43500000000000005), 'Move')
((0.67, 0.5916666666666667), 'Up')
but I would like to have more "Up" in the output(like every 0.1s). I've tried while with time.sleep() but the program crushes.
Solution 1:[1]
Simpler way to do it: add is_down property.
Example:
def on_touch_down(self, touch, pos):
self.is_down = True
<your code>
def on_touch_up(self, touch, pos):
if self.is_down:
self.is_down = False
<your code>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
