-1

I tried to initialize with pygame using the code below.

import pygame
pygame.init()

But I get 2 errors.

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

Can anyone help me?

My code is below.

# 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")
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    Please post the exact code that gave you that stack trace.. it's erroring on a line that is not in your example code. – JeffUK Jan 07 '22 at 15:33
  • are you trying to run pygame in a notebook environment with the kernel hosted in the cloud? Pygame needs access to the local video system, on your computer - it can't be run on the cloud like that, – jsbueno Jan 07 '22 at 15:53
  • Can pygame be ran on a website to run? I am using onlinegdb.com. –  Jan 07 '22 at 15:55

2 Answers2

2

You can run your code on replit.com:

replit.com/@Rabbid76/PyGame-in-browser

When creating a new repl, select the Pygame template:

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • @VihaanMody Where do you get "no output". It works fine for me. If you have problems it is related to your system. Sorry, but I cannot fix your system. I've implemented about 100 PyGame samples with Repls and all of them work fine. – Rabbid76 Jan 07 '22 at 20:37
  • Sorry, I am sure now that the problem is with the system. –  Jan 07 '22 at 21:51
0
# importing pygame module
import pygame

# importing sys module
import sys


class RunPygame(object):
    """docstring for RunPygame"""
    def __init__(self):
        pygame.init()

        self.screen = pygame.display.set_mode((300, 300))
        pygame.display.set_caption("Test")
        self.bg_color = (250, 140, 95) #for example
    

    def run_game(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
            self.screen.fill(self.bg_color)

            pygame.display.flip()

if __name__ == '__main__':
        game = RunPygame()
        game.run_game()
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 08 '22 at 13:23