2017-01-14 58 views
2

我是pygame的新手,我有這個錯誤請幫助我。TypeError:'模塊'對象在pygame中無法調用

backgrounf_image_filename = 'ubisoft.jpg' 
    mouse_image_filename = 'cursor.png' 

    import pygame 
    from pygame.locals import * 
    from sys import exit 

    pygame.init() 

    screen = pygame.display.set_mode((640, 480), 0, 32) 
    pygame.display.set_caption("Hello World!") 
    background = pygame.image.load(backgrounf_image_filename).convert() 
    mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() 

和我有一個錯誤:

Traceback (most recent call last): 
     File "C:/Users/ziyaa/PycharmProjects/pygame/helloworld.py", line 13, in <module> 
     mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() 
    TypeError: 'module' object is not callable 

    Process finished with exit code 1 
+0

的第一篇文章,其中包括完整的堆棧跟蹤:那好,值得一個upvote,一個答案:) –

+0

作爲一個人指出,你的縮進最後有點關閉。您可能會遇到問題(但這與問題無關,我將編輯該問題) –

回答

0

你這樣做:

background = pygame.image.load(backgrounf_image_filename).convert() 
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha() 

在第二個指令,你忘了你的load圖像,從而調用模塊代替的功能。

只要做到:

mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha() 
+0

thx:D但現在圖像沒有加載爲什麼它可以? –

+0

沒有加載如何?崩潰?沒有顯示?圖像位於哪裏? –

+0

沒有顯示。在項目文件夾 –

0

你的問題是你event.get循環。我用一個類似我的遊戲,其正確的方法,但是你有你接下來的幾行縮進錯誤

x, y = pygame.mouse.get_pos() 
     x -= mouse_cursor.get_width()/2 
     y -= mouse_cursor.get_height()/2 
     screen.blit(mouse_cursor, (x, y)) 
需求

被unidented或向後移動

+0

這不是問題,但可能是OP _next_問題。 –

+0

FWI你應該拼寫正確的所有變量 –

+0

這是因爲你有一個英文backgrounf。 –

相關問題