基维:什么触摸.ud方法

2024-10-02 02:27:37 发布

您现在位置:Python中文网/ 问答频道 /正文

刚开始kivy框架,在kivy painting app tutorial中有以下代码行:

touch.ud['line'] = Line(points=(touch.x, touch.y))

有人能解释一下touch.ud的确切含义吗? 使用print(help(touch.ud))返回

Help on EnhancedDictionary in module kivy.input.motionevent object:

class EnhancedDictionary(builtins.dict) ...

把所有这些放在一起,仍然不知道发生了什么。有人能特别解释一下“ud”部分吗。谢谢!在


Tags: 代码框架applinehelptutorialpointstouch
1条回答
网友
1楼 · 发布于 2024-10-02 02:27:37

让我们看一下touch parts是提供事件on_touch_XXX的参数,它是^{},因此,如果你想找到信息,你应该转到文档的那一部分,检查^{},你会得到以下结果:

ud = None

User data dictionary. Use this dictionary to save your own data on the touch.

然后,描述告诉我们,如果您想共享一些您想在_touch_xxx上的其他事件中使用的信息,则将其保存在该字典中是正确的:

def on_touch_XXX(self, touch):
    touch.ud["some_info"] = some_value

def on_touch_YYY(self, touch):
    value = touch.ud["some_info"]
    print(value)

在特定的例子中,在on_touch_down中创建的行的实例被保存,因为on_touch_move需要它来添加更多的点。在

相关问题 更多 >

    热门问题