一个小程序:图片代替鼠标移动

一个小程序:图片代替鼠标移动

程序的运行效果:

hongten_pygame

hongten_pygame

当鼠标移动到窗口内,鼠标不见了,取而代之的是图片.....

==============================================

代码部分:

==============================================

#pygame first program

import pygame
from pygame.locals import *
from sys import exit

__author__ = {'name' : 'liuzhi',
              'mail' : '646557623@qq.com',
              'blog' : 'http://www.cnblogs.com/liuzhi',
              'QQ'   : '646557623',
              'Version' : '1.0'}

BG_IMAGE = 'D:\python\test1\1.gif'
MOUSE_IMAGE = 'D:\python\test1\mouse.gif'

pygame.init()

#设置窗口的大小
screen = pygame.display.set_mode((500, 500), 0, 32)
pygame.display.set_caption('hello liuzhi')

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()

 源码位置http://files.cnblogs.com/liuzhi/test1.zip

 

原文地址:https://www.cnblogs.com/liuzhi/p/3975730.html