源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python基于pygame实现图片代替鼠标移动效果

  • 时间:2021-03-14 12:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python基于pygame实现图片代替鼠标移动效果
本文实例讲述了Python基于pygame实现图片代替鼠标移动效果。分享给大家供大家参考,具体如下: 想想现在学校pygame有几个钟了,就写了一个小程序:图片代替鼠标移动 程序的运行效果: [img]http://files.jb51.net/file_images/article/201511/20151111112627224.png?20151011112646[/img] [img]http://files.jb51.net/file_images/article/201511/20151111112651578.png?2015101111274[/img] 当鼠标移动到窗口内,鼠标不见了,取而代之的是图片..... 代码部分如下:
#pygame first program
import pygame
from 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()

完整实例代码代码点击此处[url=http://xiazai.jb51.net/201511/yuanma/pygame_mouse_pic_move_codes(jb51.net).rar]本站下载[/url]。 希望本文所述对大家Python程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部