简体   繁体   中英

moving a Image with mouse cursor in Kivy

I need to move a image with the mouse cursor in kivy it dosent mean that i want to change the mouse pointer to some image because i would then need to change the angle or that image whenever there will be a touch event .

I found that we have MotionEvent in kivy but then that is working only when we have a touch event with move or press down or up . I need something when we just move cursor without touch ?

You can use the mouse_pos variable 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM