Python新手-需要帮助打开窗口



我是python的新手,正在编写我的第一个代码。

我键入的唯一代码如下。我知道它应该打开一个空白窗口,但当我尝试运行代码时,一个窗口没有打开,终端只显示:

C:UsersdliotAppDataLocalProgramsPythonPython37-32python.exe: can't find '__main__' module in 'C:/Users/dliot/Desktop/DsCode/Game'
Process finished with exit code 1

我做错了什么?

import pygame
pygame.init()
win = pygame.display.set_mode((500,200))
while True:
pass

看起来您正在运行python3 -m Game的某个变体,而您应该执行

$ python3 game.py  # or whatever the name of your file is

或者,要使-m的调用按预期工作,请将文件重命名为__main__.py

最新更新