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

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


It works for me:

import osos.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"import pygame


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, syswith 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 contextlibwith contextlib.redirect_stdout(None):    import pygame


The source code contains a condition guarding the printing of this message:

if 'PYGAME_HIDE_SUPPORT_PROMPT' not in os.environ:    print('pygame %s' % ver)    print('Hello from the pygame community. https://www.pygame.org/contribute.html')

See this commit

This was added fairly recently (October 2018) and so far 1.9.4 was released prior to this. Once the next version > 1.9.4 is released you should simply by able to run your code with PYGAME_HIDE_SUPPORT_PROMPT= ./my_code.py to hide the message.