Pygame窗口无法从python脚本内部打开

Pygame窗口无法从python脚本内部打开,python,pygame-surface,Python,Pygame Surface,我正在尝试在Windows 10 PC上打开pygame surface。以下是打开800 x 600窗口所需的步骤。从python shell调用时,曲面将打开并正确显示,如下所示: Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32 >>> import pygame pygame 1.9.6 Hello from the pygame co

我正在尝试在Windows 10 PC上打开pygame surface。以下是打开800 x 600窗口所需的步骤。从python shell调用时,曲面将打开并正确显示,如下所示:

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> pygame.init()
(6, 0)
>>> size = (800, 600)
>>> pygame.display.set_mode(size)
<Surface(800x600x32 SW)>
>>> pygame.display.get_surface()
<Surface(800x600x32 SW)> 
文件“C:\Users\timtru\Documents\PycharmProjects\core.py”,第25行,在__
超级(Pypboy,self)。\uuuuuu初始值(*args,**kwargs)
文件“C:\Users\timtru\Documents\PycharmProjects\core.py”,第21行,在_init中__
self.window=pygame.display.set_模式((宽度、高度))
**pygame.error:没有可用的视频设备**


为什么我可以在shell中获取窗口,但在脚本中运行相同的步骤时获取“无可用视频设备”?

在程序开始时,调用pygame.init()后,需要调用

pygame.display.init()
您需要先初始化显示器,然后才能使用它。从

显示模块在初始化之前无法执行任何操作