Deck
Deck

Reputation: 3

Python Module Issue: TypeError: 'module' object is not callable

I've been attempting to develop a text adventure type game in Python (and PyGame), and thus needed a module to repeatedly blit text to the screen. After searching through a few, I downloaded KTextSurfaceWriter and installed it. Then I tried to follow the demo in the text provided here (http://www.pygame.org/project-KTextSurfaceWriter-1001-.html)

My code:

from ktextsurfacewriter import KTextSurfaceWriter

import pygame
from pygame.locals import *
import pygame.font
pygame.font.init()
screen = pygame.display.set_mode((640,480), 0, 32)

surface = pygame.surface ( (400, 400), flags = SRCALPHA, depth = 32)
surface.fill( (255,255,255,255) )

def blitSurface():
    screen.blit(surface, (50,50) )
    pygame.display.update()

blitSurface()

def waitForUserAction():
    while True:

        for event in pygame.event.get():
            if event.type == QUIT:
                import sys
                sys.exit()
            if event.type == KEYDOWN:
                return

waitForUserAction()

However, this throws back the module error at line 9. I'm fairly new to Python and most of the solutions I saw for this issue involved using the 'from [module] import' code that I already have at the beginning.

Upvotes: 0

Views: 417

Answers (2)

jia hilegass
jia hilegass

Reputation: 503

I have seen your code and soure code.

surface = pygame.surface ( (400, 400), flags = SRCALPHA, depth = 32)

In your code, "surface" is lowercase, which is a python module, so python interpreter tells you the err msg.

surface = pygame.Surface( (400,400), flags=SRCALPHA, depth=32 )

In source code, "Surface" is capital, which may be a class.

Upvotes: 0

Martijn Pieters
Martijn Pieters

Reputation: 1121744

You are calling the pygame.surface module:

surface = pygame.surface ( (400, 400), flags = SRCALPHA, depth = 32)

Either use pygame.surface.Surface() or use pygame.Surface() (note the capital S); these are both the same class but pygame.surface is the module in which it is defined.

Upvotes: 2

Related Questions