0

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.

1
  • 2
    Were you thinking of capital Surface? Python is case sensitive. Commented Jul 18, 2016 at 7:22

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I'm still not used to how case-sensitive Python can be, I guess. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.