python - import * 只允许在模块级别。使用 Pyscripter 的 Python 3.3

标签 python pygame pyscripter

一般来说,我对编程还很陌生,我刚开始使用 python 来尝试使用 pygame 制作一个简单的游戏。如果我在 Python IDLE shell 中运行以下代码,它可以正常工作,但如果我使用 Pyscripter,我会收到错误消息:

SyntaxError: import * only allowed at module level

我真的很喜欢使用 Pyscripter,因为到目前为止它使学习语法变得更加容易,但现在我不明白哪里出了问题。任何帮助都会很棒。谢谢。
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()

最佳答案

问题是当你执行 from pygame.locals import *您正在从文件而不是模块访问所有内容。当您执行 from pygame import * 之类的操作时,它应该工作。只是你只能使用import *在模块级别

关于python - import * 只允许在模块级别。使用 Pyscripter 的 Python 3.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21097806/

相关文章:

python - 为什么 __radd__ 不工作

python - 用python在pygame中制作一个8*8的棋盘

python - Pygame (python) 中翻转图像的问题

python - Pygame:绘制单个像素

python - 从 os.path.isfile() 函数接收 AttributeError

pyscripter - PyScripter 中是否有用于切换或关闭选项卡的键盘快捷键?

python - 了解类型错误: '<' not supported between instances of 'Example' and 'Example'

python - 从 self var python 获取正确的输出

python - 如何在 Cython 中初始化固定大小的整数 numpy 数组?

python - 无论我尝试多少种不同的类型,插入语句永远不会起作用。 SQLite3 pyscripter