在清华大学出版社出版的《Python程序设计》第十二章第一节中有一段示例代码,
【例12-1】显示图形界面的hello world
```python
import pygame
from pygame.locals import *
from sys import exit#初始化
background_image=r"C:\Users\11239\Pictures\ppt\ac6eddc451da81cbb78c88865f66d01609243116 (2).jpg"
mouse_image=r"C:\Users\11239\Pictures\ppt\timg (2).jpg"
pygame.init()#初始化pygame
screen=pygame.display.set_mode((640,480),0,32)#创建窗口
pygame.display.set_caption("hello world")#设置窗口标题
background=pygame.image.load(background_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(background,(0,0))
x,y=pygame.mouse.get_pos()
x-=mouse_cursor.get_width()/2
y-=mouse_cursor.get_height()/2
screen.blit(mouse_cursor,(x,y))
pygame.display.update()
(略去部分注释)发现运行之后提示: DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using int is deprecated, and may be removed in a future version of Python.
screen.blit(mouse_cursor,(x,y))
查看信息,发现需要整数,所以,将x和y转化为整数即可,即修改倒数第二行代码为:
screen.blit(mouse_cursor,(int(x),int(y)))
若不做修改,程序仍可正常运行,但从提示看来,在以后的版本中此类情况可能会影响程序运行。