Уведомления

Группа в Telegram: @pythonsu

#1 Фев. 14, 2018 19:52:17

Andrey_Golovin
Зарегистрирован: 2018-01-27
Сообщения: 35
Репутация: +  1  -
Профиль   Отправить e-mail  

AttributeError: 'Settings' object has no attribute 'screen_width'

Доброй ночи! Помогите разобраться с ошибкой. Вот скрипт

 #!/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()

Офлайн

#2 Фев. 14, 2018 19:54:12

Andrey_Golovin
Зарегистрирован: 2018-01-27
Сообщения: 35
Репутация: +  1  -
Профиль   Отправить e-mail  

AttributeError: 'Settings' object has no attribute 'screen_width'

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)
И импортируемый файл с параметрами.

Офлайн

#3 Фев. 14, 2018 20:04:12

Romissevd
От: Счастье
Зарегистрирован: 2015-03-01
Сообщения: 533
Репутация: +  76  -
Профиль   Отправить e-mail  

AttributeError: 'Settings' object has no attribute 'screen_width'

 def __init__(self):
по два подчеркивания, а не одному

Офлайн

#4 Фев. 14, 2018 20:12:57

Andrey_Golovin
Зарегистрирован: 2018-01-27
Сообщения: 35
Репутация: +  1  -
Профиль   Отправить e-mail  

AttributeError: 'Settings' object has no attribute 'screen_width'

Romissevd
Спасибо!

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version