Python基于pygame实现图片代替鼠标移动效果
作者:Hongten 时间:2023-10-24 13:33:34
本文实例讲述了Python基于pygame实现图片代替鼠标移动效果。分享给大家供大家参考,具体如下:
想想现在学校pygame有几个钟了,就写了一个小程序:图片代替鼠标移动
程序的运行效果:
当鼠标移动到窗口内,鼠标不见了,取而代之的是图片.....
代码部分如下:
#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()
完整实例代码代码点击此处本站下载。
希望本文所述对大家Python程序设计有所帮助。
标签:Python,pygame,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python爬虫开发之urllib模块详细使用方法与实例全解
2021-02-24 04:52:42
python爬虫解决验证码的思路及示例
2021-07-21 19:23:04
vue.js默认路由不加载linkActiveClass问题的解决方法
2024-05-02 16:53:25
![](https://img.aspxhome.com/file/2023/3/130153_0s.png)
10个Python面试常问的问题(小结)
2023-04-11 19:36:15
Display SQL Server Login Mode
2024-04-18 10:55:50
Vue ElementUI在el-table中使用el-popover问题
2024-05-09 15:22:15
Go编程库Sync.Pool用法示例详解
2024-02-01 04:48:21
Javascript HTML5 Canvas实现的一个画板
2024-04-10 10:39:36
JS数组去重的九种高阶方法(亲测有效)
2024-04-19 10:57:45
Python实现保证只能运行一个脚本实例
2021-04-01 06:58:39
JS验证逗号隔开可以是中文字母数字
2024-04-19 10:48:08
作为PHP程序员你要知道的另外一种日志
2023-11-15 02:06:59
![](https://img.aspxhome.com/file/2023/3/55813_0s.png)
Mysql四种分区方式以及组合分区落地实现详解
2024-01-23 05:05:25
我所理解的网页推广设计的几个要点
2011-01-25 12:37:00
![](https://img.aspxhome.com/file/UploadPic/20111/25/javascript-selectors3-23s.jpg)
python使用PIL和matplotlib获取图片像素点并合并解析
2021-09-07 15:41:45
![](https://img.aspxhome.com/file/2023/6/93606_0s.png)
ThinkPHP3.0略缩图不能保存到子目录的解决方法
2024-04-30 08:47:06
python自动化测试之破解滑动验证码
2023-12-01 09:36:25
![](https://img.aspxhome.com/file/2023/3/127913_0s.png)
基于Python编写一个宝石消消乐小游戏
2021-10-25 05:46:06
PyCharm软件无法安装lxml库的问题及解决
2023-06-04 01:54:30
![](https://img.aspxhome.com/file/2023/7/89327_0s.png)
python爬虫之利用selenium+opencv识别滑动验证并模拟登陆知乎功能
2023-10-17 22:33:37