I'm fairly new to programming in general and I just started using python to try and make a simple game using pygame. If I run the following code in the Python IDLE shell it works fine but if I use Pyscripter I get the error:
SyntaxError: import * only allowed at module level
I really like using Pyscripter because so far it has made learning the syntax much easier but now I don't understand what is wrong. Any help would be great. Thanks.
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400,300),0,32)
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()
The problem is when you execute from pygame.locals import *
you are accessing all from a file, not a module. When you do something like from pygame import *
, it should work. It is just that you can only use import *
at the module level