马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
vscode Insider, Python 3.10.5
目录结构:
project
(project)folder
(folder)main.py
(project)assets
(assets)image
(image)CrazySmile.bmp
(project)pgmore
(pgmore)image.py
代码:
project/folder/main.pyimport pygame
from .. import pgmore
pygame.init()
screen = pygame.display.set_mode((600,400))
pygame.display.set_caption('test')
ball = pgmore.image.Image("../assets/mage/CrazySmile.bmp", screen)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
ball.blit()
pygame.display.update()
project/pgmore/image.pyimport pygame
class Image:
def __init__(self, image, screen: pygame.surface.Surface):
self.image = pygame.image.load(image)
self.rect = self.image.get_rect()
self.screen = screen
def blit(self, pos=None):
if pos is None:
pos = self.rect
self.screen.blit(self.image, pos)
main.py报错信息:
Traceback (most recent call last):
File "project/folder/main.py", line 2, in <module>
from ..pgmore import image
ImportError: attempted relative import with no known parent package
|