【发布时间】:2019-09-22 15:20:47
【问题描述】:
我正在尝试在 Windows 10 PC 上打开一个 pygame 界面。以下是打开 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)>
当我在 python 脚本中执行相同的操作时,出现回溯错误:
pygame.error: No available video device**
pygame.init()
self.window = pygame.display.set_mode((width, height))
self.screen = pygame.display.get_surface()
self.background = pygame.surface.Surface(self.screen.get_size()).convert()
self.background.fill((0, 0, 0))
pygame.mouse.set_visible(True)
File "C:\Users\timtru\Documents\PycharmProjects\core.py", line 25, in __init__ super(Pypboy, self).__init__(*args, **kwargs) File "C:\Users\timtru\Documents\PycharmProjects\core.py", line 21, in __init__ self.window = pygame.display.set_mode((width, height)) **pygame.error: No available video device**
为什么我可以在 shell 中获取窗口,但在脚本中运行相同的步骤时却得到“没有可用的视频设备”?
【问题讨论】:
标签: python pygame-surface