2011-10-27 94 views
0

我正在編寫一個腳本,用於截取觸摸板輸出並在進行一些處理後發送到窗口。所以不涉及GUI。我想在某些遊標行爲發生時暫時改變遊標。我已經在網上搜索了我的能力,發現很少有文章談論使用win32api.SetCursor(),但這根本不起作用。大多數帖子都談到了使用Tkinter或wxPython更改遊標。是否有任何其他解決方案來改變光標系統範圍?使用Python臨時更改光標

回答

0

使用下面的代碼來改變系統範圍,儘管我必須恢復到退出程序下面的箭頭光標。如果還有其他更好的方法,我將非常感謝您的回覆。

from ctypes import * 
import win32con 

SetSystemCursor = windll.user32.SetSystemCursor #reference to function 
SetSystemCursor.restype = c_int #return 
SetSystemCursor.argtype = [c_int, c_int] #arguments 

LoadCursorFromFile = windll.user32.LoadCursorFromFileA #reference to function 
LoadCursorFromFile.restype = c_int #return 
LoadCursorFromFile.argtype = c_char_p #arguments 

CursorPath = "../cursor/MyCross.cur" 

NewCursor = LoadCursorFromFile(CursorPath) 

if NewCursor is None: 
    print "Error loading the cursor" 
elif SetSystemCursor(NewCursor, win32con.IDC_ARROW) == 0: 
    print "Error in setting the cursor"