Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why when import pygame, it prints the version and welcome message. How delete it?

Why is there a message when I import pygame, it prints the version and welcome message. The message reads

"pygame 1.9.4 Hello from the pygame community.  https://www.pygame.org/contribute.html"  

How can I disable this message?

like image 374
Aaron Avatar asked Jul 22 '18 11:07

Aaron


People also ask

Why does pygame initialize?

You can always initialize individual modules manually, but pygame. init() initialize all imported pygame modules is a convenient way to get everything started. The init() functions for individual modules will raise exceptions when they fail.

How do I import imports into pygame?

Open a terminal, and type 'sudo apt-get install idle pygame', enter your password and type 'y' at the prompts, if necessary. 2. After the installation completes, enter 'python' in the terminal to launch Python. Verify that it's using version 2.7 or newer, then at the Python prompt enter 'import pygame'.


2 Answers

It works for me:

import os os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide" import pygame 
like image 190
Eduardo Dalapicola Avatar answered Sep 20 '22 15:09

Eduardo Dalapicola


I didn't see a natural way to do it (yours is the only Google result for this that I could find), but I did achieve the same thing by temporarily disabling stdout while importing pygame.

import os, sys with open(os.devnull, 'w') as f:     # disable stdout     oldstdout = sys.stdout     sys.stdout = f      import pygame      # enable stdout     sys.stdout = oldstdout 

Here's the alternative suggested by @Mad Physicist:

import contextlib with contextlib.redirect_stdout(None):     import pygame 
like image 34
tsbertalan Avatar answered Sep 16 '22 15:09

tsbertalan