在Kivy中使用鼠标光标移动图像 [英] moving a Image with mouse cursor in Kivy

查看:76
本文介绍了在Kivy中使用鼠标光标移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用鼠标光标移动图像,这确实意味着我想将鼠标指针更改为某个图像,因为每当发生触摸事件时,我就需要更改角度或该图像. /p>

我发现我们的运动事件是奇异的,但是只有当我们通过move或按下或向上或向下触摸事件时,该事件才起作用.当我们不触摸就移动光标时我需要些东西吗?

解决方案

您可以在Window类中使用mouse_pos变量.例如:

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()

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()

这篇关于在Kivy中使用鼠标光标移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆