为什么会出现错误“ pygame.error:没有可用的视频设备”?

时间:2019-12-10 16:12:17

标签: pygame

这是我的代码:

import pygame, sys
from pygame.locals import *

pygame.init()
#set up window
DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32) 


#set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)

#draw on the surface object
DISPLAYSURF.fill(WHITE)
pygame.draw.polygon(DISPLAYSURF, GREEN, ((146, 0), (291,106), (236, 277), (56, 277), (0,106)))
pygame.draw.line(DISPLAYURF, BLUE, (60,60), (120,60), 4)
pygame.draw.line(DISPLAYSURF, BLUE, (120,60), (60,120))
pygame.draw.line(DISPLAYSURF, BLUE, (60, 120), (120,120), 4)
pygame.draw.circle(DISPLAYSURF, BLUE, (300,50), 20, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (300, 250, 40, 80), 1)
pygame.draw.rect(DISPLAYSURF, RED, (200,150,100,50))

pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[480][380]= BLACK
pixObj[482][382]= BLACK
pixObj[484][384]= BLACK
pixObj[486][386]= BLACK
pixObj[488][388]= BLACK
del pixObj

while True:
  for event in pygame.event.get():
    if event.type == QUIT:
      pygame.quit()
      sys.exit()
  pygame.display.update()

我真的不确定该错误意味着什么,我尝试对其进行谷歌搜索,但实际上没有其他人收到此错误消息。从字面上看,它与我在PDF上试图执行的代码完全相同,但是没有用。我刚开始pygame。 这是错误消息:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32)
pygame.error: No available video device

1 个答案:

答案 0 :(得分:1)

尝试在pygame存储库中搜索有关特定错误的信息和示例。似乎表明必须定义系统。

下面的代码来自
https://github.com/search?q=pygame.error+No+available+video+device&type=Code

## If you get the no available video device error, copy and paste the below code ##
import platform
if platform.system() == "Windows":
### If you get the no available video device error, copy and paste the above code ###

另外,有一些答案的SO帖子:
pygame.error: No available video device


**更新:以下链接似乎在repl.it中有一个有效的pygame。

https://repl.it/@amasad/simple-platformer