I want to change my cursor image (everywhere on screen) when my program is running.
I try to load image with win32gui and then use win32api to change cursor image, but s
Changing the system cursor is not recommended. For the sake of curiosity, it can be done with SetSystemCursor
, example
ctypes.windll.user32.SetSystemCursor(hcursor, 32512) #OCR_NORMAL
See documentation for OCR_NORMAL
and other cursor constants.
I would not recommend this at all for python, because it is difficult to restore the cursor, so the user will be stuck with a new cursor unless he changes the cursor through the system settings. You can try to save the old cursor and restore it, but this method fails if your program exits abnormally.
hold = win32gui.LoadImage(0, 32512, win32con.IMAGE_CURSOR,
0, 0, win32con.LR_SHARED )
hsave = ctypes.windll.user32.CopyImage(hold, win32con.IMAGE_CURSOR,
0, 0, win32con.LR_COPYFROMRESOURCE)
hnew = win32gui.LoadImage(0, 'file.cur',
win32con.IMAGE_CURSOR, 0, 0, win32con.LR_LOADFROMFILE);
ctypes.windll.user32.SetSystemCursor(hcursor, 32512)
time.sleep(5)
#restore the old cursor
ctypes.windll.user32.SetSystemCursor(hsave, 32512)