|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打不开图片,然后显示一片漆黑
这个是提示我错误的地方
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
=============== RESTART: C:\Users\Administrator\Desktop\小甲鱼.py ===============
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\小甲鱼.py", line 14, in <module>
turtle=pygame.image.load("turtle.png")
pygame.error: Couldn't open turtle.png
>>>
=============================== RESTART: Shell ===============================
>>>
这个是我的代码
import pygame
import sys
#初始化pygame
pygame.init()
size=width,hight=1500,800
speed=[-2,1]
bg=(255,255,255)
#创建指定大小的窗口
screen=pygame.display.set_mode(size)
#设置窗口标题
pygame.display.set_caption("初次见面,请多关照!")
#加载图片
turtle=pygame.image.load("turtle.png")
#获得图像的矩形位置
position=turtle.get_rect()
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
#移动图像
position=position.move(speed)
if position.left<0 or position.right>width:
#图像翻转
turtle=pygame.tiansform.flip(turtle,True,False)
#反方向移动
speed[0]=-speed[0]
if position.top<0 or position.bottom>height:
speed[1]=-speed[1]
#填充背景
screen.fill(bg)
#更新图像
sereen.blit(trutle,position)
#更新界面
pygame.display.flip()
#延迟10毫秒
pygame.time.delay(10)
图片你有么,和py文件是不是一个目录,不是写全路径
|
|