0

My script is opening many other scripts. In one of the scripts (Player), I try to open the Window script. If I start the Window script, there is no issue, but when I start the main script, which starts the player script, which then tries to start the Window script, there is an issue. The issue says, that:

there is no Module named 'Window'.

Every script is in a file named scripts. so every script, but the main.

here is the main script

import pygame
import sys

from pygame.locals import *
pygame.init()

from scripts.player import Player 
from scripts.Inputs import Input
from scripts.Window import Window

class Game(object):
    def __init__(self):
        self.Player = Player(10,10)
        self.Input = Input()
        self.Window = Window(800,600)

    def update(self):
        self.Window.update(60)
        self.Input.Input()
        self.Player.draw(self.Window.display)

    def run(self):
        while True:
            self.update()

Game().run()

and here is the player script:

import pygame
from Window import Window

class Player(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.image = pygame.Surface((10,10))

    def draw(self, display):
        pygame.draw.rect(display,(255,255,255),(self.x,self.y,self.image.get_width(),self.image.get_height())) 
Levi
  • 51
  • 5
  • 1
    What are the names of the files contained in the `scripts` directory? – 0x5453 Sep 15 '21 at 17:40
  • Player.py, Inputs.py, Window.py – Levi Sep 15 '21 at 22:02
  • In the question, you are importing the files from the main script, aren't you? Make sure that you didn't copy-paste the line `from scripts.Window import *` in the `player` script without removing `scripts.` because the `player` file is in the ```scripts\``` folder. – D_00 Sep 16 '21 at 07:03
  • Yes I know. I haven’t copied it. I edited the post, so u see what I’ve imported. Maybe I am not able to open a script twice… – Levi Sep 16 '21 at 09:41

0 Answers0