39

Why does the first widget example in kivy lead to an orange circle in the middle of the yellow one when you right click on the canvas and a pure yellow one when you left click?

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse

class MyPaintWidget(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d/2, touch.y - d/2), size=(d, d))


class MyPaintApp(App):
    def build(self):
        return MyPaintWidget()


if __name__ == '__main__':
    MyPaintApp().run()
Cœur
  • 37,241
  • 25
  • 195
  • 267
Terrence Brannon
  • 4,760
  • 7
  • 42
  • 61
  • This definitely freaked me out when I first saw it, had no idea why a Button would do that. Never worked with a touch-based library before. – John C Mar 29 '21 at 17:01

2 Answers2

39

To disable multi-touch emulation, add this to your source file containing your main function, before any other kivy modules are imported:

from kivy.config import Config
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
TimSC
  • 1,459
  • 16
  • 20
  • 1
    As far I can tell, it's not necessary to do this before other kivy modules are imported. I did your `Config.set[...]` command after all my imports and it worked fine. – Asker Aug 14 '20 at 03:12
15

It's multitouch emulation, you can see how to disable it here

http://kivy.org/docs/api-kivy.input.providers.mouse.html

Tshirtman
  • 5,859
  • 1
  • 19
  • 26
  • 5
    (1) You can clear them by left clicking and re-setting a new simulated multi-touch. (2) You can set more than one. (3) Look at the Kivy examples/demo/pictures sample for a great example utilizing multi-touch emulation. – Mark Dec 31 '12 at 07:15
  • 2
    Link-only answers really aren't considered good practice (as you probably NOW know). Please summarize the contents in your answer. – CodeMouse92 Jul 22 '17 at 21:14
  • This works on Windows, but causes problems on Android. Here's the exception I get if I try to open a DropDown sub class menu: raise WidgetException( [WARNING] stderr: kivy.uix.widget.WidgetException: Cannot add to window, it already has a parent – Jean-Pierre Schnyder Sep 29 '21 at 19:34