2016-08-18 9 views
0

私はちょうどpythonとpygameを使ってポーカープログラムを構築し始めました。そして、カードの画像をたくさんダウンロードしました。私は画像のテストプログラムを作成し始めました:pygame 'module'オブジェクトは呼び出し可能ではありません

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") 

初めての間、それは完全に動作します。しかし、私はこれを得る:

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 

私はすべてを試しましたが、それはまだそれを言う。それを機能させるために私ができることはありますか?

PSカードを保存するフォルダは、Python35のscriptsフォルダにあります。

アップデート:私はpygame.image.loadですべてpygame.imageを交換しましたが、今私の代わりにこれを取得:

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 

答えて

1

pygame.imageはそれほど呼び出すことはできません関数ではありません。代わりにpygame.image.load()を使用します。

出典:http://www.pygame.org/docs/ref/image.html

編集:pythonのファイルを見つけることができないので、あなたはおそらく、新しいエラーを取得している

。ファイルの絶対パスを使用する必要があります。例えば。 pygame.image.load('C:\\pictures\\2_of_clubs.png')

ps。あなたの質問にそれらのモジュールをすべてリストする必要はありません。不必要に長い間質問をしています。

2

問題は、pygame.imageは実際には機能ではなく、モジュール(したがってエラーのテキスト)です。イメージをロードするには、関数pygame.image.load(filename)を使用します。

関連する問題