Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pygame开始运行时出错_Python_Python 3.x_Git_Pygame - Fatal编程技术网

Python pygame开始运行时出错

Python pygame开始运行时出错,python,python-3.x,git,pygame,Python,Python 3.x,Git,Pygame,运行控制台时出错: --> python3 -m poetry init --no-interaction --name repl_python3_SycoBaksGame This command will guide you through creating your pyproject.toml config. You can specify a package in the following forms: - A single name (requests) -

运行控制台时出错:



--> python3 -m poetry init --no-interaction --name repl_python3_SycoBaksGame

This command will guide you through creating your pyproject.toml config.


You can specify a package in the following forms:
  - A single name (requests)
  - A name and a constraint (requests ^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - An url (https://example.com/packages/my-package-0.1.0.tar.gz)



pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
xcb_connection_has_error() returned true
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
xcb_connection_has_error() returned true
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
 

我的代码:

import pygame

#Canvas Creation

pygame.init()

win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("SycoBaks Game")

#Position
x = 250
y = 250

#Size
width = 20
height = 20

#Velocity/Time
speed = 5


#SycoBak Main GameFrame

run = True

while not run:
    pygame.time.delay(100)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
            
    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
      x=x-1
    
    if keys[pygame.K_RIGHT]:
      x=x+1
    
    if keys[pygame.K_UP]:
      y=y-1

    if keys[pygame.K_DOWN]:
      y=y+1



    pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))

    pygame.display.update()

pygame.quit()

如果有什么帮助我解决了这个错误,我会很高兴,因为我的代码没有任何问题,这可能是pygame依赖性问题,但我不知道*

pygame.init()正在尝试为您初始化所有pygame模块

我认为这是导入一个需要一些工作(您不需要)的模块,并强制您执行一些不需要的代码。尝试逐个导入所需的模块。
你可以
init()
你需要的每个模块。

有一个输入错误:
而不是运行:
,但是
run
被设置为
True
,所以你的主循环永远不会运行。运行时需要
。此错误报告:(和其他地方)表明这可能是Alsa的用户权限错误。尝试以root用户身份临时运行。还有:@Kingsley,可能不是打字错误。。。我认为这更像是一个允许OP在不需要的时候运行/不运行代码的标志。。。SycoBak请提供一个