Reputation: 90
I've been trying to use the widget from this tutorial http://kivy.org/docs/tutorials/firstwidget.html# I'm unable to make any touches on the widget, it doesn't recognize my clicks as touches. How do I get it to detect my clicks as touch responses? This is the code I have now,
from kivy.app import App
from kivy.uix.widget import Widget
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 buil(self):
return MyPaintWidget()
if __name__ == '__main__':
MyPaintApp().run()
Upvotes: 0
Views: 384
Reputation: 29488
1) You have a typo, defining the method buil
where it should be build
. That means the method doesn't ever do anything as it doesn't get called, so the paint widget is never created or displayed.
2) You don't import Color or Ellipse. This would raise an error in the on_touch_down method even if the above typo was correct.
Below is a fixed version that works for me. Maybe both errors are just typos in your pasting to here, but they certainly both break the app - and the first would cause exactly the behaviour you see.
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics.context_instructions import Color
from kivy.graphics.vertex_instructions import 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()
Upvotes: 1