Moving image with mouse cursor in Kivy

I need to move the image with the mouse cursor in kivy, it dosent means I want to change the mouse pointer to some image because then I will need to change the angle or this image whenever there is a touch event.

I found that we have a MotionEvent in kivy, but then it only works when we have a touch event with move or push or up. Do I need something when we just move the cursor without touching?

0


source to share


1 answer


You can use a variable mouse_pos

in the Window class. For example:



import kivy
kivy.require('1.0.8')

from kivy.core.window import Window
from kivy.app import App
from kivy.clock import Clock
from functools import partial


class MyMouse(App):

    def __init__(self, **kwargs):
        super(MyMouse, self).__init__(**kwargs)
        Clock.schedule_interval(partial(self.my_callback), 0.05)

    def my_callback(self, dt):
        print Window.mouse_pos

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

      

+3


source







All Articles