Python – Tkinter mouse color

Tkinter mouse color… here is a solution to the problem.

Tkinter mouse color

I’m working on a project right now and I need a black mouse cursor like this :

enter image description here

I used root.config(cursor="arrow black black"), but it didn’t want to change the color of the cursor. I’m using Windows, and if this helps, Windows has a black cursor installed by default.

Can anyone help me with this?

Edit:

how to change the mouse pointer color tkinter? Doesn’t work for me.

I can change the appearance of the cursor, but not the color.

Solution

On Windows systems, arrow pointers map to native IDC_ARROW pointer, whose color you cannot control in tkinter.

Of course, Windows does have a black mouse pointer, but the appearance of the pointer used depends on the current color scheme (Control Panel – Mouse – Poter), so you won’t see it unless you change the scheme.
The app should not touch it because it is entirely a user preference.

However, the black pointer file is located arrow_r.cur%windir%\Cursors\, so we can use it directly when we need to:

import tkinter as tk
import os

root = tk. Tk()
path = '@%s' % os.path.join(os.environ['WINDIR'], 'Cursors/arrow_r.cur').replace('\\', '/')

root.configure(cursor=path)
root.mainloop()

It is also worth noting that the black hands are available in medium and large variants – arrow_rm.cur and arrow_rl.cur, respectively.

Related Problems and Solutions