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)
hcursor = 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)
- edited: renamed
hnew
to hcursor
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…