在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()
该错误显示为:
NameError:名称“屏幕”未定义
该如何解决?我相信我正确安装了pygame和pip。
答案 0 :(得分:0)
您没有定义名称“屏幕”。使用相同的变量引用screen.fill()
中的变量,将其更改为resolution.fill()
答案 1 :(得分:-1)
只需将第五行更改为:
screen = pygame.display.set_mode((1920, 1080))