导入一系列模块并在其中访问类时遇到问题。
这是我的代码:
import sys, os
for path, name, files in os.walk(os.getcwd()[:os.getcwd().rindex("Mario")+5]):
sys.path.insert(0, os.path.join(path))
from pygame.locals import *
import pygame, Screen
WIDTH, HEIGHT = SIZE = 1200, 675
running = True
screen = pygame.display.set_mode(SIZE, SRCALPHA)
current = None
screen_menu = Screen.Menu().add_widget(Widget.Button(WIDTH/2-25, HEIGHT/2-25, 50, 30))
跑步时我得到:
Traceback (most recent call last):
File "I:\Computing\Python\Mario\Global.py", line 5, in <module>
import pygame, Screen
File "I:\Computing\Python\Mario\screen\Screen.py", line 5, in <module>
import pygame, Global
File "I:\Computing\Python\Mario\Global.py", line 11, in <module>
screen_menu = Screen.Menu().add_widget(Widget.Button(WIDTH/2-25, HEIGHT/2-25, 50, 30))
AttributeError: 'module' object has no attribute 'Menu'
[Finished in 2.9s with exit code 1]
有谁知道为什么会发生这种情况,我已经导入了它,而 Menu 只是 Screen 中的一个类,如果需要,我可以给你 Screen 类!