Python基于pygame实现图片代替鼠标移动效果
本文实例讲述了Python基于pygame实现图片代替鼠标移动效果。分享给大家供大家参考,具体如下:
想想现在学校pygame有几个钟了,就写了一个小程序:图片代替鼠标移动
程序的运行效果:


当鼠标移动到窗口内,鼠标不见了,取而代之的是图片.....
代码部分如下:
#pygame first program
import pygame
from pygame.locals import *
from sys import exit
__author__ = {'name' : 'Hongten',
'mail' : '[email protected]',
'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程序设计有所帮助。
相关推荐
快递小可 2020-08-16
RocNg 2020-05-03
unit00 2020-03-03
fly00love 2020-02-10
wyqwilliam 2020-01-09
柠檬班 2020-01-06
JasonYeung 2019-05-17
elizabethxxy 2019-05-14
hfuturer 2019-03-18
crackerzhou 2019-05-08
迷途风景 2019-05-14
野先生 2019-03-13
一叶不知秋 2019-03-07
chouliqingke 2019-03-04
远哥的小迷弟 2019-03-03
pengkunstone 2018-02-17
sulindong0 2018-01-19
SnowLi 2018-01-15
hanxia 2019-02-26