Posts: 12
Joined: Sun Sep 30, 2012 8:35 pm

Prevent Joystick.get_button output?

Sun Sep 30, 2012 8:42 pm


I want to create a small "text menu" in which i want to select item with only a gamepad connected. To do this, i thought it would be a great idea to use the pygame's Joystick module, but i keep running into a problem due to some sort of debug mode? this code:

jb = j.get_button(1)

Outputs a "print" on the screen:

SDL_JoystickGetButton value:1
SDL_JoystickGetButton value:0

Is there any (easy, for a newbie like me) solution to fix this?

Best regards /Jon

Posts: 1382
Joined: Thu Aug 18, 2011 9:21 pm

Re: Prevent Joystick.get_button output?

Sun Sep 30, 2012 11:13 pm

I posted on the forum about '' which might be of help, possibly...
note: I may or may not know what I'm talking about...

Posts: 6
Joined: Thu Nov 17, 2011 11:19 pm

Re: Prevent Joystick.get_button output?

Sat Oct 06, 2012 5:49 pm

Hi Jerd,

I've come across this issue with some code I wrote and did some digging as to why it was doing it.

Apparently when pygame v1.9.1 was released, a few lines of debug code was left in. This is what you are seeing.

See ... 00110.html

The reason, but not a solution. I'm hoping that one day typing

Code: Select all

sudo apt-get install python-pygame
will update to a new version of pygame where this debug code has been removed.


Posts: 66
Joined: Sat Jul 28, 2012 11:58 am
Location: Germany

Re: Prevent Joystick.get_button output?

Thu Mar 07, 2013 6:37 pm

Any solutions for this problem available now?

Neil Munday
Posts: 111
Joined: Tue Mar 18, 2014 8:52 pm
Location: UK

Re: Prevent Joystick.get_button output?

Tue Mar 18, 2014 8:57 pm

Hi all,

I too experienced the same annoying SDL debug statements and after much searching for a solution I decided to build pygame from source myself and patch the offending file (joystick.c).

Here is a BASH script that should do the trick.

I thought I'd share it here in case it helps anyone else out.

The script assumes that you have the gcc compiler, Make etc. installed.



Code: Select all


# Build script for pygame 1.9 under Raspbian by Neil Munday (
# March 2014


echo "Removing system installed pygame..."
sudo apt-get remove python-pygame

echo "Installing dependencies..."
sudo apt-get install libv4l-dev mercurial python-dev python-numpy ffmpeg libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev

if [ ! -e /usr/include/linux/videodev.h ]; then
	if [ ! -e /usr/include/libv4l1-videodev.h ]; then
		echo "Error: /usr/include/libv4l1-videodev.h does not exist!"
		exit 1
	sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h

mkdir -p $buildDir

cd $buildDir

if [ -e $pygameDir]; then
	echo "Removing previous pygame source"
	rm -rf $pygameDir

echo "Downloading pygame source..."

echo "Unpacking pygame source..."
tar xvfz pygame-1.9.1release.tar.gz
echo "Patching joystick.c ..."
cd pygame-1.9.1release
cp src/joystick.c src/joystick.c-orig
grep -v printf src/joystick.c-orig > src/joystick.c

echo "Building pygame (this will take some time!) ..."
python build

echo "Installing pygame..."
sudo python install

echo "Done!" -> The Pi Entertainment System for all your gaming needs

Return to “Python”