0

So I just finished up with a good amount of learning python and working on learning pygame. So I am following along with this free online book, and the first thing of code in the book of making a window with hello world on the top is giving me an error:

Heres the code:

import pygame, sys
from pygame.locals import *

pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

pygame.display.update()

Heres the error:

  File "pygame.py", line 9
    if event.type == QUIT:
     ^
IndentationError: expected an indented block

Thanks in advance!

  • This code works fine at my end. Are you sure all the identations are spaces or tabs? – gkso Jan 03 '17 at 01:05
  • 1
    Possible duplicate of [Why am I getting "IndentationError: expected an indented block"?](http://stackoverflow.com/questions/4446366/why-am-i-getting-indentationerror-expected-an-indented-block) – l'L'l Jan 03 '17 at 01:38

2 Answers2

1

As presented, this code works fine at this end. If you are still having a problem I suggest you look at tabs vs spaces in your editor.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
1

Be aware that Python is a space sensitive language. The compiler actually cares whether there is a mix of spaces and tabs throughout the program.

Stick to one of either kind throughout your code and this will resolve the issue.

jrocha
  • 11
  • 1