本文實例講述了Python基于pygame實現圖片代替鼠標移動效果。分享給大家供大家參考,具體如下:
想想現在學校pygame有幾個鐘了,就寫了一個小程序:圖片代替鼠標移動
程序的運行效果:


當鼠標移動到窗口內,鼠標不見了,取而代之的是圖片.....
代碼部分如下:
#pygame first programimport pygamefrom pygame.locals import *from sys import exit__author__ = {'name' : 'Hongten', 'mail' : 'hongtenzone@foxmail.com', 'QQ' : '648719819', 'Version' : '1.0'}BG_IMAGE = 'c://test//1.gif'MOUSE_IMAGE = 'c://test//mouse.gif'pygame.init()#設置窗口的大小screen = pygame.display.set_mode((500, 500), 0, 32)pygame.display.set_caption('Hongten/'s First Pygame Program')bg = pygame.image.load(BG_IMAGE).convert()mouse_cursor = pygame.image.load(MOUSE_IMAGE).convert_alpha()while True: for event in pygame.event.get(): if event.type == QUIT: exit() screen.blit(bg, (0, 0)) #鼠標的x,y坐標 x, y = pygame.mouse.get_pos() #隱藏鼠標 pygame.mouse.set_visible(False) x -= mouse_cursor.get_width() / 2 y -= mouse_cursor.get_height() / 2 #用其他圖形代替鼠標 screen.blit(mouse_cursor, (x, y)) pygame.display.update()完整實例代碼代碼點擊此處本站下載。
希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答
圖片精選