I'm having a problem trying to import another python script correctly using pygame.
This is my file structure:
folder 1
a1.py
folder 2
a2.py
img1.py
folder 3
img1.bmp
a1.py
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()
When running a1.py, it is opening img1.py (same as a2.py) but for whatever reason, img1.py is only opening the image for a2.py and not for a1.py (img1.py and error are displayed later).
a2.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()
img1.py
import pygame
import os, sys
tiger = pygame.image.load(os.path.join('Images','tiger.bmp'))
tigerX = 10
tigerY = 10
img1.py is supposed to open tiger.bmp (img1.bmp), it works correctly in a2.py but for some reason when trying to do it with a1.py it doesn't work and get the following error:
Traceback (most recent call last):
File "F:\Raspberry Engine\Engine.py", line 6, in <module>
from tiger import *
ModuleNotFoundError: No module named 'tiger'
Could anyone help? I need a1.py to do the same thing as a2.py from a different directory.