2016-08-18 1 views
0

J'ai donc commencé à utiliser python et pygame pour commencer à construire un programme de poker, et j'ai téléchargé un tas d'images pour les cartes. J'ai commencé à faire un programme de test pour les images:objet 'module' de pygame non appelable

import pygame 
pygame.init() 

screen = pygame.display.set_mode((1200, 675)) #Sets the screen to a 16:9 ratio display 
pygame.display.set_caption('Poker Program')  #Used to set the window name as whatever's in the brackets 
feltGreen = (0,200,0)       #What is used for the color (r,g,b)(the higher the number, the lighter the colour) 
screen.fill(feltGreen) 
pygame.display.update()       #Updates the screen 

twoc = pygame.image("2_of_clubs.png") 
twod = pygame.image("2_of_diamonds.png") 
twoh = pygame.image("2_of_hearts.png") 
twos = pygame.image("2_of_spades.png") 
threec = pygame.image("3_of_clubs.png") 
threed = pygame.image("3_of_diamonds.png") 
threeh = pygame.image("3_of_hearts.png") 
threes = pygame.image("3_of_spades.png") 

Pour la première fois, cela fonctionne parfaitement. Mais alors je reçois ceci:

Traceback (most recent call last): 
    File "C:/Users/Z & Z Azam/Desktop/New folder (2)/Python Stuff/PycharmProjects/ProjectGambler/Graphics-Cards.py", line 15, in <module> 
    twoc = pygame.image("2_of_clubs.png") 
TypeError: 'module' object is not callable 

J'ai tout essayé, mais ça dit toujours ça. Y a-t-il quelque chose que je puisse faire pour que ça marche? PS Le dossier dans lequel je stocke les cartes se trouve dans le dossier scripts de Python35.

Mise à jour: Je l'ai remplacé tous les pygame.image avec pygame.image.load, mais maintenant je reçois ceci:

Traceback (most recent call last): 
    File "C:/Users/Z & Z Azam/Desktop/New folder (2)/Python Stuff/PycharmProjects/ProjectGambler/Graphics-Cards.py", line 15, in <module> 
    twoc = pygame.image.load("2_of_clubs.png")   #Lines 15-66 bring all the cards into the program 
pygame.error: Couldn't open 2_of_clubs.png 

Répondre

1

pygame.image n'est pas une fonction est donc pas appelable. Vous voulez probablement utiliser pygame.image.load() à la place.

Source: http://www.pygame.org/docs/ref/image.html

Edit:

Vous obtenez probablement la nouvelle erreur car python ne peut pas trouver le fichier. Vous devez utiliser le chemin absolu du fichier. Par exemple. pygame.image.load('C:\\pictures\\2_of_clubs.png').

Ps. vous n'avez pas besoin de lister tous ces modules dans votre question. Cela rend la question inutilement longue.

2

Le problème est que pygame.image n'est pas réellement une fonction - c'est un module (d'où le texte de l'erreur). Pour charger une image, utilisez la fonction pygame.image.load(filename).