【发布时间】:2022-01-07 15:28:55
【问题描述】:
我尝试使用下面的代码使用 pygame 进行初始化。
import pygame
pygame.init()
但我得到 2 个错误。
pygame 2.0.1 (SDL 2.0.14, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
ftruncate() failed: File too large
Failed to create secure directory (//.config/pulse): No such file or directory
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4732:(_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:4732:(_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:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
File "main.py", line 3, in <module>
pygame.key.get_repeat()
pygame.error: video system not initialized
谁能帮帮我?
我的代码如下。
# importing pygame module
import pygame
# importing sys module
import sys
# initialising pygame
pygame.init()
# creating display
display = pygame.display.set_mode((300, 300))
# creating a running loop
while True:
# creating a loop to check events that
# are occuring
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# checking if keydown event happened or not
if event.type == pygame.KEYDOWN:
# if keydown event happened
# than printing a string to output
print("A key has been pressed")
【问题讨论】:
-
请发布为您提供堆栈跟踪的确切代码。它在您的示例代码中没有的行上出错。
-
您是否尝试在笔记本环境中运行 pygame,内核托管在云中? Pygame 需要访问本地视频系统,在您的计算机上 - 它不能像那样在云上运行,
-
pygame可以在网站上运行吗?我正在使用 onlinegdb.com。