1

It doesn't crash when I comment out the gameloop, and I can't figure out what is going on here. When I run the code through the debugger it says that there is an attribute error: '_ModuleLock' object has no attribute 'name'. Other searches on google hasn't really helped me, I'm still very new please help thank you.

code:

import pygame, sys, random
from pygame.locals import*

WINWIDTH = 1200
WINHEIGHT = 800
CARDTHUMBWIDTH = 50
CARDTHUMBHEIGHT = 80
FPS = 30
FPSCLOCK = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((WINWIDTH,WINHEIGHT))
pygame.display.set_caption('NBA Card Game')
pygame.init()

lakersDeck = ['Lakers_01.png', 'Lakers_02.png', 'Lakers_03.png', 'Lakers_04.png', 'Lakers_05.png',
              'Lakers_06.png', 'Lakers_07.png', 'Lakers_08.png', 'Lakers_09.png', 'Lakers_10.png',
              'Lakers_11.png', 'Lakers_12.png', 'Lakers_13.png', 'Lakers_14.png', 'Lakers_15.png',
              'Lakers_16.png', 'Lakers_17.png', 'Lakers_18.png', 'Lakers_19.png', 'Lakers_20.png']


#shuffling deck, getting first hand, deleting drawn cards from deck
shuffleDeck = random.sample(lakersDeck, len(lakersDeck))
playerDeck = shuffleDeck
playerHand = []
playerHand.append(playerDeck[0])
playerHand.append(playerDeck[1])
playerHand.append(playerDeck[2])
playerHand.append(playerDeck[3])
for cards in range(4):
    del playerDeck[0]

print(playerDeck)
print(playerHand)

#display playmat etc
font = pygame.font.SysFont(None, 30)
userTextPrompt = "20, 725"
playMat = pygame.image.load('playmat.png')
detailBox = pygame.image.load('detailBox.png')
DISPLAYSURF.blit(playMat, (0,0))

#defining images and rects            
IMAGES = {
0: pygame.image.load(playerHand[0]),
1: pygame.image.load(playerHand[1]),                         
2: pygame.image.load(playerHand[2]),
3: pygame.image.load(playerHand[3])}

RECTS = [pygame.Rect(17, 635, 50, 80), pygame.Rect(75, 635, 50, 80),
         pygame.Rect(133, 635, 50, 80), pygame.Rect(191, 635, 50, 80)]

#game loop
while True:
    currentImageIndex = None
    mouse_pos = pygame.mouse.get_pos()
    for i, rect in enumerate(RECTS):
        if rect.collidepoint(mouse_pos):
            currentImageIndex = i
            break
    if currentImageIndex is not None:
        DISPLAYSURF.blit(IMAGES[currentImageIndex], RECTS[currentImageIndex])


    FPSCLOCK.tick(FPS)
    pygame.display.update()




pygame.display.update()

error:

Traceback (most recent call last):
  File "C:/Users/shyot/Desktop/python/Bball Card/Cards/main3.py", line 1, in <module>
    import pygame, sys, random
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 148, in __enter__
  File "<frozen importlib._bootstrap>", line 174, in _get_module_lock
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "C:\Users\shyot\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "C:\Users\shyot\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 66, in dispatch_line
    self.user_line(frame)
  File "C:\Users\shyot\AppData\Local\Programs\Python\Python36\lib\idlelib\debugger.py", line 24, in user_line
    self.gui.interaction(message, frame)
AttributeError: '_ModuleLock' object has no attribute 'name'
immeeh
  • 59
  • 5
  • Perhaps you have some name collision, do you have a file or folder with the name of the module you're trying to import? Import each module on a [separate line](https://www.python.org/dev/peps/pep-0008/#imports) to help track down the problem. Additionally your code runs for me, showing a screen and images when I mouseover the defined rects. You should handle events correctly, i.e. call `pygame.event.get()` and loop over the events. – import random Mar 28 '18 at 01:57
  • Thanks, I'll look into it! I haven't found any file or folder module with a similar name, but I'll keep looking. When I run the program, I see the images but I don't get very far because it crashes promptly. edit: after separating the imports, the debugger mentions only pygame – immeeh Mar 28 '18 at 09:49

0 Answers0