简体   繁体   English

pg.event.set_allowed([pg.KEYDOWN,pg.KEYUP,pg.QUIT])pygame.error:视频系统未初始化

[英]pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT]) pygame.error: video system not initialized

Getting error in this file when running the Mario game I downloaded the code from the following link( https://github.com/Ja1r0/DQN-play-SuperMario ) when trying to run the file super_mario.py, I am getting this above error(pygame.error video system not initialized). 运行Mario游戏时在此文件中出现错误我尝试通过运行文件super_mario.py时从以下链接( https://github.com/Ja1r0/DQN-play-SuperMario )下载代码,我在上面得到了此信息错误(pygame.error视频系统未初始化)。

I am using ubuntu 18.04 widget in windows10. 我在Windows10中使用ubuntu 18.04小部件。

import platform

p_name = platform.system()
print(p_name)

import os
import pygame as pg
from . import tools
from . import constants as c
ORIGINAL_CAPTION = c.ORIGINAL_CAPTION

current_dir = os.path.dirname(os.path.realpath(__file__))
'''
os.environ['SDL_VIDEO_CENTERED'] = '1'
pg.init()
pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
pg.display.set_caption(c.ORIGINAL_CAPTION)
SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
SCREEN_RECT = SCREEN.get_rect()
FONTS = tools.load_all_fonts(os.path.join("resources", "fonts"))
MUSIC = tools.load_all_music(os.path.join("resources", "music"))
GFX = tools.load_all_gfx(os.path.join("resources", "graphics"))
SFX = tools.load_all_sfx(os.path.join("resources", "sound"))
# dev env
'''
if True:#p_name == "aaa":
    import os
    import pygame as pg
    from . import tools
    from . import constants as c
    ORIGINAL_CAPTION = c.ORIGINAL_CAPTION


    os.environ['SDL_VIDEO_CENTERED'] = '1'
    pg.init()
    pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
    pg.display.set_caption(c.ORIGINAL_CAPTION)
    SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
    SCREEN_RECT = SCREEN.get_rect()
    FONTS = tools.load_all_fonts(os.path.join("resources", "fonts"))
    MUSIC = tools.load_all_music(os.path.join("resources", "music"))
    GFX = tools.load_all_gfx(os.path.join("resources", "graphics"))
    SFX = tools.load_all_sfx(os.path.join("resources", "sound"))
# aws
else:
    import os
    # import pygame as pg
    from . import tools
    from . import constants as c

    ORIGINAL_CAPTION = c.ORIGINAL_CAPTION

    os.environ['SDL_VIDEO_CENTERED'] = '1'
    os.environ["SDL_VIDEODRIVER"] = "dummy"
    os.environ["SDL_AUDIODRIVER"] = "dummy"
    import pygame as pg

    pg.init()

    pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])
    pg.display.set_caption(c.ORIGINAL_CAPTION)
    SCREEN = pg.display.set_mode(c.SCREEN_SIZE, 0, 32)
    SCREEN_RECT = SCREEN.get_rect()
    FONTS = tools.load_all_fonts(os.path.join(current_dir, "..", "resources", "fonts"))
    MUSIC = tools.load_all_music(os.path.join(current_dir, "..",  "resources", "music"))
    GFX = tools.load_all_gfx(os.path.join(current_dir, "..",  "resources", "graphics"))
    SFX = tools.load_all_sfx(os.path.join(current_dir, "..",  "resources", "sound"))

You said you're using [the] ubuntu 18.04 widget in windows10 (I guess you're talking about the Windows Subsystem for Linux), which does not come with a video display. 您说过您正在[the] ubuntu 18.04 widget in windows10使用[the] ubuntu 18.04 widget in windows10 (我想您是在说Linux的Windows子系统),它没有视频显示。 It's console only, unless you install an X-server like eg xming. 它仅是控制台,除非您安装了诸如xming之类的X服务器。

The error video system not initialized tells you exactly that: there's no video system that could draw a window avaiable. video system not initialized的错误video system not initialized准确地告诉您:没有视频系统可以绘制窗口。

So you could either try to install an X-server or run your code from within your Windows 10 installation, not the WSL. 因此,您可以尝试安装X服务器,也可以从Windows 10安装而不是WSL中运行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM