我在尝试使用pygame正确导入另一个python脚本时遇到问题。
这是我的文件结构:
folder 1
a1.py
folder 2
a2.py
img1.py
folder 3
img1.bmp
import os, sys
import pygame
sys.path.insert(0, os.path.join('E:\Raspberry
Engine\projects\TestGame\Scripts'))
from tiger import *
from ASTRO2 import *
(ScrnWidth, ScrnHeight) = (1080, 720)
screen = pygame.display.set_mode((ScrnWidth, ScrnHeight))
pygame.display.set_caption("Raspberry Engine")
backgroundcolour = (255,255,255)
screen.fill(backgroundcolour)
Running = True
while Running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
Running = False
pygame.quit()
screen.blit(tiger,(tigerX,TigerY))
pygame.display.flip()
运行a1.py
时,它正在打开img1.py
(与a2.py
相同),但无论出于何种原因,img1.py
仅打开a2.py
的图像,不适用于a1.py
(img1.py
,稍后会显示错误。)
import pygame
from tiger import *
from ASTRO2 import *
(width, height) = (1080, 720)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Test Game")
backgroundcolour = (255,255,255)
screen.fill(backgroundcolour)
Running = True
while Running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
Running = False
pygame.quit()
screen.blit(tiger,(tigerX,tigerY))
screen.blit(ASTRO2,(ASTRO2X,ASTRO2Y))
pygame.display.flip()
import pygame
import os, sys
tiger = pygame.image.load(os.path.join('Images','tiger.bmp'))
tigerX = 10
tigerY = 10
img1.py
应该打开tiger.bmp
(img1.bmp
),它可以在a2.py
中正常运行,但出于某种原因尝试使用a1.py
没有工作并得到以下错误:
Traceback (most recent call last):
File "F:\Raspberry Engine\Engine.py", line 6, in <module>
from tiger import *
ModuleNotFoundError: No module named 'tiger'
有人可以帮忙吗?我需要a1.py
与来自不同目录的a2.py做同样的事情。