我遇到AttributeError问题:'设置'对象没有属性' screen'。请帮帮我,代码如下:
class Settings():
def __init__(self):
self.screen_width=1200
self.screen_height=800
self.bg_color=(230,230,230)
import sys
import pygame
from settings import Settings
def run_game():
pygame.init()
ai_settings=Settings()
screen=pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen.height))
pygame.display.set_caption("Inwazja obcych")
while True:
screen.fill(ai_settings.bg_color)
for event in pygame.event.get():
if event.type==pygame.quit:
sys.exit()
pygame.display.flip()
run_game()
答案 0 :(得分:4)
它应该是screen_height
的下划线。您的代码改为screen.height