Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pygame';屏幕';未定义_Python_Pygame - Fatal编程技术网

Python pygame';屏幕';未定义

Python pygame';屏幕';未定义,python,pygame,Python,Pygame,在Python速成课程之后,我复制了这个输入,并在运行时出错 import os import pygame def play_game(): #Creates Screen resolution = pygame.display.set_mode((1920, 1080)) pygame.init() pygame.display.set_caption('Game') #Colors the background bg_color = (230

在Python速成课程之后,我复制了这个输入,并在运行时出错

import os
import pygame
def play_game():
    #Creates Screen
    resolution = pygame.display.set_mode((1920, 1080))
    pygame.init()
    pygame.display.set_caption('Game')
    #Colors the background
    bg_color = (230,230,230)
    #Starts the game
    while True:
        #Sets background color
        screen.fill(bg_color)
        #Looks for user inputs
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

                #updates the screen
                pygame.display.flip()



play_game()
错误内容如下:

名称错误:未定义名称“屏幕”


我该如何解决这个问题?我相信我正确安装了pygame和pip。

只需将第五行更改为:

screen = pygame.display.set_mode((1920, 1080))

您没有定义名称“screen”。使用相同的变量来引用
screen.fill()
,将其更改为
resolution.fill()

是否更改了变量名称?在示例中,Was
resolution=pygame.display.set_mode((1920,1080))
实际上
screen=pygame.display.set_mode((1920,1080))
在示例中..?显示表面的名称(即
pygame.display.set_mode
返回)是
分辨率
而不是
屏幕
。只需将其重命名为
屏幕