I'm trying to learn to make games using pygame
module in python
. I'm using the ubuntu terminal in Windows 10. This is my program.
# 1 - Import library
import os
os.environ['SDL_AUDIODRIVER'] = 'dummy'
import pygame
from pygame.locals import *
# 2 - Initialize the game
print("-1")
pygame.init()
pygame.display.list_modes()
print("0")
width, height = 640, 480
print("00")
screen=pygame.display.set_mode((width, height))
print("1")
# 3 - Load images
player = pygame.image.load("resources/images/virus.png")
print("3")
# 4 - keep looping through
while 1:
# 5 - clear the screen before drawing it again
screen.fill(0)
print("4")
# 6 - draw the screen elements
screen.blit(player, (100,100))
print("5")
# 7 - update the screen
pygame.display.flip()
# 8 - loop through the events
for event in pygame.event.get():
# check if the event is the X button
if event.type==pygame.QUIT:
# if it is quit the game
pygame.quit()
exit(0)
As soon as I run the program, I get this error.
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
-1
Traceback (most recent call last):
File "pythongame.py", line 10, in <module>
pygame.display.list_modes()
pygame.error: video system not initialized
I looked at many posts but of no use. Please tell me how to resolve this.
If you inizialize the pygame "modules" that need to using pygame.init() and an error is thrown, this error is not displayed or anithyng like that. You can initialize all "internal pygame modules" using something like pygame.display.init() If you do it this way a traceback get's printed. I also don't have any trouble using pycharm to execute this program. Maybe it's something with the unbuntu terminal that you use. Try initializing the display class using pygame.display.init() Here a link about what I said: pygame.org
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.