Python Kivy在移动小部件时获取其在分散中的位置

Python Kivy在移动小部件时获取其在分散中的位置,python,python-2.7,kivy,Python,Python 2.7,Kivy,我找了很多,但没找到解决办法。我想抓住一个小部件在一个kivy分散,并得到它的位置,每次我移动它。所以它可以这样说: def onmove_in_scatter(args): x = args[0] y = args[1] print("You are currently here: "+str(x)+":"+str(y)) 在我移动小部件时调用函数是很重要的。当我想做类似的事情时,我会覆盖on\u touch\u move 下面是一个完整的工作示例。(把cat.png

我找了很多,但没找到解决办法。我想抓住一个小部件在一个kivy分散,并得到它的位置,每次我移动它。所以它可以这样说:

def onmove_in_scatter(args):
    x = args[0]
    y = args[1]
    print("You are currently here: "+str(x)+":"+str(y))

在我移动小部件时调用函数是很重要的。

当我想做类似的事情时,我会覆盖on\u touch\u move

下面是一个完整的工作示例。(把cat.png放在某处…)

导入kivy
导入日期时间
从kivy.app导入应用程序
从kivy.uix.widget导入widget
从kivy.uix.button导入按钮
来自kivy工厂进口工厂
从kivy.lang导入生成器
从kivy.uix.floatlayout导入floatlayout
从kivy.uix.scatter导入scatter
生成器。加载\u字符串(“”)
:
id:酷
#位置:200200
#尺寸:300300
图片:
id:img
资料来源:“cat.png”
允许拉伸:真
尺码:酷。尺码

: MyScatter: """) 类散射(散射): def on_touch_move(self,touch):#魔法时间!!!! res=super(我的猫,我自己)。触碰移动(触碰) 如果是:#你可以做点什么! 打印自我中心 返回res P类(浮动布局): 通过 类别MyApp(应用程序): def生成(自): 返回P() 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': MyApp().run()

为什么不能解决您的问题?
import kivy
import datetime

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.factory import Factory
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scatter import Scatter




Builder.load_string("""
<MyScatter>:
    id: cool
    #pos: 200, 200
    #size: 300,300
    Image:
        id: img
        source: "cat.png"
        allow_stretch:  True
        size: cool.size
<P>:
    MyScatter:


""")


class MyScatter(Scatter):


    def on_touch_move(self, touch): #magic time!!!!
        res =  super(MyScatter, self).on_touch_move(touch)
        if res: #Yay do something!
            print self.center
        return res
class P(FloatLayout):
    pass


class MyApp(App):


    def build(self):
        return P()


if __name__ == '__main__':
    MyApp().run()