How to get keyboard input in pygame?

You can get the events from pygame and then watch out for the KEYDOWN event, instead of looking at the keys returned by get_pressed()(which gives you keys that are currently pressed down, whereas the KEYDOWN event shows you which keys were pressed down on that frame). What’s happening with your code right now is that … Read more

Unable to install Pygame using pip

Steps to install PyGame using pip Install build dependencies (on linux): sudo apt-get build-dep python-pygame Install mercurial to use hg (on linux): sudo apt-get install mercurial On Windows you can use the installer: Download Use pip to install PyGame: pip install hg+http://bitbucket.org/pygame/pygame If the above gives freetype-config: not found error (on Linux), then try sudo … Read more

How to disable welcome message when importing pygame

As can be seen in the source code, the message is not printed if the environment variable PYGAME_HIDE_SUPPORT_PROMPT is set. So the following code could be used to import pygame without printing the message: import os os.environ[‘PYGAME_HIDE_SUPPORT_PROMPT’] = “hide” import pygame Note that the value does not have to be “hide” but can be anything … Read more

How to block calls to print?

Python lets you overwrite standard output (stdout) with any file object. This should work cross platform and write to the null device. import sys, os # Disable def blockPrint(): sys.stdout = open(os.devnull, ‘w’) # Restore def enablePrint(): sys.stdout = sys.__stdout__ print ‘This will print’ blockPrint() print “This won’t” enablePrint() print “This will too” If you … Read more