I am trying to learn how to make a game of Snake in Python. I found a tutorial using pygame, but I’m having trouble making it work. Here’s my code :
import os, pygame
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
dis = pygame.display.set_mode((400,300))
pygame.display.set_caption('Test')
while 1 :
pygame.display.update()
pygame.quit()
quit()
The problem is that the game window simply doesn’t open. I get ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred
errors but I think those are related to the sound. Other than that, no message in the console.
The code is running in a debian 11 VM inside a Windows 7 host.
2
Answers
Delete the
os.environ["SDL_VIDEODRIVER"] = "dummy"
From this
As the documentation states, the dummy mode is designed to create an SDL environment without opening a window. Because in this case, we do actually want to create a window, You should remove the line
os.environ["SDL_VIDEODRIVER"] = "dummy"
. This does also mean that you don’t have to import theos
module.