Recognizing touch shapes
There is a useful tool provided by Kivy that permits us to recognize the shape of the touch that is performed. In this recipe, we will go through the foundations of using it.
Getting ready
In this recipe, we will use the Kv language for the design of the widgets, so we assume that the reader is familiar with the Kv language. Also, this recipe will use the common button and label widgets for reference.
How to do it…
Follow these steps:
- First, in the KV file, define a button and an empty label:
<MyW>: Button: id: button1 pos: 0,0 text: 'Hello' Label: id: label1 pos: 50, 200 text: ''
- In the class of the widget in the Python code, we need to override the method
on_touch_move
. - Change the button position to the information in
touch.pos ...
Get Kivy Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.