鱼C论坛

 找回密码
 立即注册
查看: 786|回复: 3

[已解决]在编写的时候出了一些问题

[复制链接]
发表于 2019-6-28 00:31:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 /盘龙:/ 于 2019-6-28 00:41 编辑

我的代码是这样的:

  1. import pygame
  2. import sys

  3. pygame.init()

  4. size = wideth,height = 600,400
  5. speed = [-2,1]
  6. bg = (255,255,255)

  7. screen = pygame.display.set_mode(size)

  8. pygame.display.set_caption("初次见面,请大家多多关照!")

  9. tutle = pygame.image.load("11=.jpg")

  10. position = tutle.get_rect()


  11. while True:
  12.     for event in pygame.event.get():
  13.         if event.type == pygame.QUIT:
  14.             sys.exit()

  15.     position = position.move(speed)

  16.     if position.left < 0 or position.right > width:
  17.         tutle = pygame.trasform.flip(tutle, True , False )
  18.         speed[0] = -speed[0]

  19.     if position.top < 0 or position.bottom > height:
  20.         speed[1] = -speed[1]


  21.     screen.fill(bg)

  22.     screen.blit(tutle,position)

  23.     pygame.display.flip()

  24.     pygame.time.delay(10)

复制代码



然后我尝试运行程序
        它总显示:

  Traceback (most recent call last):
  File "E:/0基础学习python/我的游戏/发疯的乌龟", line 14, in <module>
    tutle = pygame.image.load("11=.jpg")
pygame.error: Couldn't open 11=.jpg


** 11=。jpg 是我的一张照片**

求大神帮忙解释+解决
最佳答案
2019-6-28 00:40:02
文件要在程序所在的当前目录。你的这个图能正常打开么?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-6-28 00:40:02 | 显示全部楼层    本楼为最佳答案   
文件要在程序所在的当前目录。你的这个图能正常打开么?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-28 09:49:20 | 显示全部楼层
本帖最后由 /盘龙:/ 于 2019-6-28 09:50 编辑
凌九霄 发表于 2019-6-28 00:40
文件要在程序所在的当前目录。你的这个图能正常打开么?


我打得开
但程序就是显示打不开
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-6-28 10:43:22 | 显示全部楼层
现在打的开了,可是他又跳出一个新的错误
  1. Traceback (most recent call last):
  2.   File "E:\0基础学习python\我的游戏\发疯的乌龟.py", line 26, in <module>
  3.     if position.left < 0 or position.right > width:
  4. NameError: name 'width' is not defined
复制代码


更新后的代码长这样:
  1. import pygame
  2. import sys

  3. pygame.init()

  4. size = wideth,height = 600,400
  5. speed = [-2,1]
  6. bg = (255,255,255)

  7. screen = pygame.display.set_mode(size)

  8. pygame.display.set_caption("初次见面,请大家多多关照!")

  9. tutle = pygame.image.load("11=.jpg")

  10. position = tutle.get_rect()


  11. while True:
  12.     for event in pygame.event.get():
  13.         if event.type == pygame.QUIT:
  14.             sys.exit()

  15.     position = position.move(speed)

  16.     if position.left < 0 or position.right > width:
  17.         tutle = pygame.transform.flip(tutle, True , False )
  18.         speed[0] = -speed[0]

  19.     if position.top < 0 or position.bottom > height:
  20.         speed[1] = -speed[1]


  21.     screen.fill(bg)

  22.     screen.blit(tutle,position)

  23.     pygame.display.flip()

  24.     pygame.time.delay(10)

复制代码

我该怎么办?难不成问小甲鱼?我的等级又太低,问不了他……哎……
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-3 10:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表