Faegano
Posts: 3
Joined: Tue Dec 31, 2013 12:49 am

Can't run pygame script before starting x.

Tue Dec 31, 2013 12:57 am

I recently got a raspberry pi for Christmas and have created some very simple script in order to draw a circle on the screen with python, using pygame. This runs fine after starting up the GUI and activating it from the LXTerminal, however if I enter "python Circle.py" into the terminal after start up but before I start the GUI with "startx" the screen goes black and nothing happens.
Could anybody explain to me what is happening here.

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Can't run pygame script before starting x.

Fri Jan 03, 2014 8:37 am

The startx command runs X11 and established a graphical environment for your system. Without this, or any other graphical system running, then you won't be able to draw circles and the like.

Faegano
Posts: 3
Joined: Tue Dec 31, 2013 12:49 am

Re: Can't run pygame script before starting x.

Wed Jan 08, 2014 8:05 am

Ok, thank you. I understand now :D . Does this mean that the only way to run my script is through the terminal after starting the GUI?

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: Can't run pygame script before starting x.

Wed Jan 08, 2014 10:12 am

Correct. Pygame needs an active "GUI" to display anything.
You can either run your script from a bash terminal in the GUI or using IDLE.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Faegano
Posts: 3
Joined: Tue Dec 31, 2013 12:49 am

Re: Can't run pygame script before starting x.

Wed Jan 08, 2014 10:06 pm

Thanks for the help :) .

User avatar
Douglas6
Posts: 4860
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Can't run pygame script before starting x.

Wed Jan 08, 2014 10:18 pm

That's just not true. I have some code somewhere that uses pygame writing to the Linux framebuffer. It was based on pyscope, from our friends at Adafruit.

Yup, I hauled out the code. You don't need X-windows for pygame, necessarily.

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Can't run pygame script before starting x.

Thu Jan 09, 2014 9:30 am

The key point is that a graphical environment is required. This could be X11, Qt or whatever but a library of graphical primitives will be required to write into the framestore for that graphical interface. Any program, be it Python, C/C++ as examples, may have one or more bindings of these graphical libraries with which it will inter-operate in order to carry out its function.

More details, specific to Pygame, can be found at http://www.pygame.org/wiki/gui. There is at least one discussion on this forum http://www.raspberrypi.org/phpBB3/viewt ... =32&t=7709

Or try Googling "python with X"
https://www.google.co.uk/search?q=pytho ... e&ie=UTF-8

Return to “Beginners”