简体   繁体   English

Kivy:在桌面上隐藏鼠标光标

[英]Kivy: Hide mouse cursor on desktop

I have a fullscreen app and I'm trying to hide the mouse cursor. 我有一个全屏应用程序,我试图隐藏鼠标光标。 The setup is Kivy 1.9.0 on Python 3.4.1 for Windows , using the prepared packages. 使用准备好的软件包,使用适用于Windows的 Python 3.4.1上的Kivy 1.9.0进行设置。

I have tried the following approaches, with no success: 我尝试了以下方法,没有成功:

1- Using Config object: 1-使用Config对象:

from kivy.config import Config
Config.set("graphics", "show_cursor", 0)

2- Editing .kivy\\config.ini: 2-编辑.kivy \\ config.ini:

[graphics]
.
.
.
show_cursor = 0

3- Using pygame: 3-使用pygame:

import pygame
pygame.init()
pygame.mouse.set_visible(False)

4- Moving the mouse off-screen: 4-将鼠标移出屏幕:

def move_mouse_away(etype, motionevent):
  # this one doesn't get called at all
  Window.mouse_pos = [1400, 1000]

Window.bind(on_motion=move_mouse_away)

5- Using Clock for a similar effect: 5-使用Clock获得类似效果:

Clock.schedule_interval(self._reset_mouse, 0.05)

def _reset_mouse(self, time):
  Window.mouse_pos = [1400, 1400]

I'm a little out of ideas now. 我现在有点想法了。

I just read the documentation, tried it and fixed it (version 1.9.0). 我只是阅读文档,尝试并修复它(版本1.9.0)。 To hide the cursor from the application window permanently (even if you are using a touchscreen) : 要永久隐藏应用程序窗口中的光标(即使您使用的是触摸屏):

>>> from kivy.config import Config
>>> Config.set('graphics','show_cursor','0')
>>> Config.write()
>>> quit()

I use a touch screen (LG 19MB15T) which works 'out_of_the_box'. 我使用触摸屏(LG 19MB15T)工作'out_of_the_box'。

I'm having the same kind of problem: I need to hide or change my mouse cursor in a kivy app. 我遇到了同样的问题:我需要隐藏或更改我的鼠标光标在一个kivy应用程序。

I don't have a perfect solution only a partial one: 我没有一个完美的解决方案只有一个部分:

from kivy.uix.widget import Widget
from kivy.core.window import Window
import win32api

class NoCursorWindow(Widget):

    def __init__(self, **kwargs):
        super(NoCursorWindow, self).__init__(**kwargs)

        Window.bind(mouse_pos=self.on_mouse_pos)

    def on_mouse_pos(self, *args):
        win32api.SetCursor(None)


if __name__ == '__main__':
    from kivy.base import runTouchApp
    runTouchApp(NoCursorWindow())

It works only partially: The problem when you use win32api.SetCursor() is that when the mouse moves, the window gets a WM_SETCURSOR Message which changes the cursor back to default. 它只能部分工作:当你使用win32api.SetCursor()时的问题是,当鼠标移动时,窗口会得到一个WM_SETCURSOR消息,它将光标改回默认值。 This is why the win32api.SetCursor() must be triggered for each change of the mouse_pos . 这就是为什么必须为mouse_pos每次更改触发win32api.SetCursor()mouse_pos

But even like that sometimes we can see the default cursor blinking. 但有时我们可以看到默认光标闪烁。

If anyone knows how to hook the WM_SETCURSOR , to prevent the call back of the default cursor, it could solve this... 如果有人知道如何挂钩WM_SETCURSOR ,以防止回调默认光标,它可以解决这个问题......

You can use Window.show_cursor 您可以使用Window.show_cursor

It was added in kivy version 1.9.1 它是在kivy版本1.9.1中添加的

from kivy.core.window import Window
Window.show_cursor = False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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