简体   繁体   English

python_pygame - FileNotFoundError:没有这样的文件或目录

[英]python_pygame - FileNotFoundError: No such file or directory

Hello I am following the pygame game code and I get the following error and post a question.您好,我正在关注 pygame 游戏代码,我收到以下错误并发布问题。 When I run it, the screen pops up and then disappears immediately.The background color is also executed without saving.当我运行它时,屏幕弹出然后立即消失。背景颜色也执行而不保存。 (Mac OS) (苹果系统)

import pygame

pygame.init() # 초기화 (반드시 필요)

#화면 크기  설정
screen_width = 480 # 가로 크기
screen_height = 640 # 세로 크기
screen = pygame.display.set_mode((screen_width, screen_height))

# 화면 타이틀 설정
pygame.display.set_caption("Kim Game") # 게임 이름

# 배경 이미지 블로오기
background = pygame.image.load(("r'C:/Users/king/Desktop/practica/pygame_basic/background.png"))

# 이벤트 루프 
running = True # 게임이 진행중인가?
while running:
    for event in pygame.event.get(): # 어떤 이벤트가 발생하였는가?
        if event.type == pygame.QUIT: # 창이 닫히는 이벤트가 발생하였는가?
            running = false # 게임이 진행중이 아님

    screen.blit(background, (0, 0)) # 배경 그리기

    pygame.display.update() # 게임화면을 다시 그리기      

# prgame 종료
pygame.quit

Execution FileNotFoundError: No such file or directory.执行 FileNotFoundError:没有这样的文件或目录。

r must be a prefix, not the content of the string. r必须是前缀,而不是字符串的内容。 It has to be r"string" instead of "r'string" :它必须是r"string"而不是"r'string"

background = pygame.image.load(("r'C:/Users/king/Desktop/practica/pygame_basic/background.png"))

background = pygame.image.load(r"C:/Users/king/Desktop/practica/pygame_basic/background.png")

String with prefix 'r' or 'R' are called raw strings and treat backslashes as literal characters.带有前缀 'r' 或 'R' 的字符串称为原始字符串,并将反斜杠视为文字字符。 See String and Bytes literals .请参阅字符串和字节文字

this error means that there is a file that does not exists in your game directory you have to add an image called background.png in the pygame_basic folder此错误意味着您的游戏目录中不存在一个文件,您必须在 pygame_basic 文件夹中添加一个名为 background.png 的图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pygame 错误:FileNotFoundError:没有这样的文件或目录 - Pygame Error : FileNotFoundError: No such file or directory Python 3-FileNotFoundError:[Errno 2]没有这样的文件或目录 - Python 3 - FileNotFoundError: [Errno 2] No such file or directory FIleNotFoundError:没有这样的文件或目录 Ubuntu Python - FIleNotFoundError: No such file or Directory Ubuntu Python python:FileNotFoundError:[Errno 2]没有这样的文件或目录 - python: FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError:[错误2]没有这样的文件或目录 - Python FileNotFoundError: [Errno 2] No such file or directory Python FileNotFoundError: [Errno 2] 没有这样的文件或目录: - Python FileNotFoundError: [Errno 2] No such file or directory: SublimeREPL FileNotFoundError(2, "没有这样的文件或目录:'python'") - SublimeREPL FileNotFoundError(2, "No such file or directory: 'python'") FileNotFoundError: [Errno 2] 没有这样的文件或目录 [Python] - FileNotFoundError: [Errno 2] No such file or directory [Python] 无法打开资源文件,pygame 错误:“FileNotFoundError:没有这样的文件或目录。” - Could not open resource file, pygame error: "FileNotFoundError: No such file or directory." Pygame 错误:FileNotFoundError:没有这样的文件或目录。 他们已经在同一个文件夹中 - Pygame Error : FileNotFoundError: No such file or directory. They are already in the same folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM