pygame.error:没有可用的视频设备?怎么了?重复错误
我当时在Python工作,我刚开始使用PyGame,我正在使用一个教程,但它说“ Trackback(最近的电话最后一次):file'main.py',win = pygame.display.set_mode中的第5行((500,500) )pygame.Error:没有可用的视频设备” 有人可以解释一下这个错误告诉我什么,因为在无数的互联网搜索之后,我仍然没有发现任何帮助。这是我的代码。
import pygame
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("Client")
clientnumber = 0
win.fill((255, 255, 255))
class player():
def __init__(self, x, y, width, height, color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = (x, y, width, height)
self.vel = 3
def draw(self, win):
pygame.draw.rect(win, self.color, self.rect)
def move(self):
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
self.x -= self.vel
if key[pygame.K_RIGHT]:
self.x += self.vel
if key[pygame.K_UP]:
self.y -= self.vel
if key[pygame.K_DOWN]:
self.y += self.vel
self.rect = (self.x, self.y, self.width, self.height)
def redrawWindow(win, player):
win.fill((255, 255, 255))
player.draw(win)
pygame.display.update()
def main():
run = True
p = player(50, 50, 100, 100, (0,255,0))
clock = pygame.time.Clock()
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
p.move()
redrawWindow(win, p)
main()
I was working in python and I just started with pygame and I am using a tutorial but it says"Traceback (most recent call last): file "main.py", line 5 in win=pygame.display.set_mode((500,500)) pygame.error: No available video device"
can someone please explain what this error is telling me because after countless internet searches I still found nothing that helped. here is my code.
import pygame
pygame.init()
win = pygame.display.set_mode((500,500))
pygame.display.set_caption("Client")
clientnumber = 0
win.fill((255, 255, 255))
class player():
def __init__(self, x, y, width, height, color):
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color
self.rect = (x, y, width, height)
self.vel = 3
def draw(self, win):
pygame.draw.rect(win, self.color, self.rect)
def move(self):
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
self.x -= self.vel
if key[pygame.K_RIGHT]:
self.x += self.vel
if key[pygame.K_UP]:
self.y -= self.vel
if key[pygame.K_DOWN]:
self.y += self.vel
self.rect = (self.x, self.y, self.width, self.height)
def redrawWindow(win, player):
win.fill((255, 255, 255))
player.draw(win)
pygame.display.update()
def main():
run = True
p = player(50, 50, 100, 100, (0,255,0))
clock = pygame.time.Clock()
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.quit()
p.move()
redrawWindow(win, p)
main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PyGame
需要在运行代码的计算机上访问视频卡和图形模式(以及监视)。如果您在replagit
上运行它,则它将在服务器上运行代码,该代码通常不会在图形模式下运行,而在文本模式下运行。您必须选择模板
pygame
才能运行可以运行pygame
的特殊版本。PyGame
needs access to video card and graphics mode (and monitor) on computer on which it runs code. If you run it onreplit
then it runs code on server which usually doesn't run in graphics mode but in text mode.You have to select template
PyGame
to run special version which can runPyGame
.