0

我已经在我的 Ubuntu 上安装了 kivy 并连接了一个触摸屏,但是当我触摸屏幕时,kivy 没有检测到这一点。

检测鼠标点击没问题,只是触摸不起作用。

我已经在 config.ini 中进行了更改:`

mouse = mouse; 
mtdev_%(name)s = probesysfs,provider=mtdev; hid_%(name)s = probesysfs,provider=hidinput 

那是我的代码:

from kivy.app import App

从 kivy.uix.widget 导入小部件

类触摸输入(小部件):

def on_touch_down(self, touch):
    print(touch)
def on_touch_move(self, touch):
    print(touch)
def on_touch_up(self, touch):
    print("RELEASED!",touch)

类 SimpleKivy4(应用程序):

def build(self):
    return TouchInput()

如果name == " main ": SimpleKivy4().run()

有人知道为什么 kivy 没有检测到我的触摸输入吗?

先感谢您。

4

1 回答 1

0

虽然您已经定义了on_touch_*(self, touch)函数,但仅仅定义它是不够的。Window模块有一个方法,on_touch_*但它当前绑定到 None。它是 Window 模块,而不是您自己的类/小部件,它管理您的应用程序的整个窗口,调用诸如运动和触摸之类的回调。在 input.motionevent 的文档下,它有以下关于如何监听(使用你的回调)的动作/触摸事件:

def on_touch_down(self, touch):
    # Receives a motion event with the [pos] profile
    pass
Window.bind(on_touch_down=on_touch_down)

你错过了Window.bind(window_method=my_function)电话。

于 2020-06-09T14:54:20.723 回答