Найти - Пользователи
Полная версия: AttributeError: 'Settings' object has no attribute 'screen_width'
Начало » Python для новичков » AttributeError: 'Settings' object has no attribute 'screen_width'
1
Andrey_Golovin
Доброй ночи! Помогите разобраться с ошибкой. Вот скрипт
 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import pygame
from settings import Settings
def run_game():
	#Инициализирует pygame, setting и объект экрана.
	pygame.init()
	ai_settings = Settings()
	screen = pygame.display.set_mode(
	     (ai_settings.screen_width, ai_settings.screen_height))
	pygame.display.set_caption("Alien Invasion")
	
	#Запуск основного цикла.
	while True:
		#Отслеживание клавиатуры и мыши.
		for event in pygame.event.get():
		    if event.type == pygame.QUIT:
                        sys.exet()
				
		#При каждом проходе цикла перерисовывается экран
		screen.fill(ai_settings.bg_color)
		
		#Отображение последнего прорисованного экрана.
		pygame.display.flip()
run_game()
Andrey_Golovin
Traceback (most recent call last):
File “./alien_invasion.py”, line 30, in <module>
run_game()
File “./alien_invasion.py”, line 14, in run_game
(ai_settings.screen_width, ai_settings.screen_height))
AttributeError: ‘Settings’ object has no attribute ‘screen_width’
Ошибка.
 #!/usr/bin/ python3
# -*- coding: utf-8 -*-
class Settings():
	"""Класс для хранения всех настроек игры Alien Invasion."""
	def _init_(self):
		"""Инициализирует настройки игры."""
		#Параметры экрана
		self.screen_width = 800
		self.screen_height = 600
		self.bg_color = (230, 230, 230)
И импортируемый файл с параметрами.
Romissevd
 def __init__(self):
по два подчеркивания, а не одному
Andrey_Golovin
Romissevd
Спасибо!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB