pygame.error:没有可用的视频设备?怎么了?重复错误

发布于 2025-01-24 19:01:32 字数 1412 浏览 2 评论 0原文

我当时在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的十字路口 2025-01-31 19:01:32

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 on replit 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 run PyGame.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文