我自己编写了一个类
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("Alien Invasion")
bg_color=(230,230,230)
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
screen.fill(ai_settings.bg_color)
pygame.display.flip()
run_game()
但是最后的结果是这样的
Traceback (most recent call last):
File "alien_invasion", line 5, in
from settings import Settings
ModuleNotFoundError: No module named 'settings'
我不知道到底是什么原因,是path问题还是我的设置有问题,我用的是geany