简体   繁体   中英

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.

I have tried the following approaches, with no success:

1- Using Config object:

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

2- Editing .kivy\\config.ini:

[graphics]
.
.
.
show_cursor = 0

3- Using pygame:

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

4- Moving the mouse off-screen:

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:

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). 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'.

I'm having the same kind of problem: I need to hide or change my mouse cursor in a kivy app.

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. This is why the win32api.SetCursor() must be triggered for each change of the 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...

You can use Window.show_cursor

It was added in kivy version 1.9.1

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

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