Python Kivy应用程序没有';我认不出我的笔记本电脑的触摸功能';触摸板
我一直在尝试使用本教程中的小部件 我无法在小部件上进行任何触摸,它无法将我的点击识别为触摸。我如何让它检测我的点击作为触摸响应? 这是我现在掌握的密码Python Kivy应用程序没有';我认不出我的笔记本电脑的触摸功能';触摸板,python,click,touch,kivy,Python,Click,Touch,Kivy,我一直在尝试使用本教程中的小部件 我无法在小部件上进行任何触摸,它无法将我的点击识别为触摸。我如何让它检测我的点击作为触摸响应? 这是我现在掌握的密码 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
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()
1) 您有一个输入错误,定义了方法buil
应该在哪里build
。这意味着该方法不会执行任何操作,因为它不会被调用,因此不会创建或显示paint小部件
2) 不导入颜色或椭圆。即使上述输入正确,这也会在on_touch_down方法中引发错误
下面是一个适用于我的固定版本。也许这两个错误都只是你粘贴到这里时的输入错误,但它们肯定都会破坏应用程序,而第一个错误恰恰会导致你看到的行为
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()