0

I am creating a game using pygame, and separed it into many modules. I have added a new one for displaying the gamer's stats.

After setting up a basic pygame window, I tried to run the main code, but when I tried to open the stats window, I got an error telling me that my module (stat), hasn't an attribute named main: my main function in the module (but it does !).

I tried after that to import the main function by an other way : from stat import main, but it told me afterwards that python is not able to import the module stat.

I tried to modify the recurion limit to, but nothing changed...

So I hope that someone could help me, and here is how I'm importing the module :

from stat import main as stat

This is how it is used in my code:

if 190 <= mouse[0] <= 390 and 180 <= mouse[1] <= 240:
    color_3 = YELLOW
    if click[0] == 1:
        stat(window)
else:
    color_3 = BLACK

And here is almost all what ther is in my stats module (I did'nt added some global variables, and the pictures loading)

def main(window):
    global stat_count, stat
    pygame.dispaly.set_caption('Your stats')

    while stat:
        stat_count +=1
        if stat_count >= 27:
            stat_count = 0

        events = pygame.event.get()
        
        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()

        draw(window)
        clock.tick(27)

    def main(window):
    global stat_count, stat
    pygame.dispaly.set_caption('Your stats')

    while stat:
        stat_count +=1
        if stat_count >= 27:
            stat_count = 0

        events = pygame.event.get()
        
        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()

        draw(window)
        clock.tick(27)

def draw(window):
    global stat_count

    window.fill(BLUE)
    window.blit(bg[stat_count//3], (0, 100))

    pygame.display.update()
isen
  • 53
  • 9
  • First you say that you try to use `import main from stat`, but later you say that the module is called `stats`. Did you mean to use `import main from stats`? – mkrieger1 Sep 27 '20 at 11:33
  • Oh sorry, you'r true, it was just a careless mistake while writing the question; my module is named stat, so I'am importing it by : `import main from stat` – isen Sep 27 '20 at 11:50
  • My distro (Anaconda) already has a stat module. Try renaming your module to gamestat.py. That fixes the issue for me. – Mike67 Sep 27 '20 at 12:45
  • It is now working ! Thank you very much, I was struggling on it for a while.. – isen Sep 27 '20 at 13:18

0 Answers0