anakinmorgan
Posts: 13
Joined: Wed Jul 18, 2012 6:17 pm

The MagPi problems

Thu Jul 26, 2012 11:30 am

Guys and Girls Help please
I am trying to run some of the examples in magipi mags
The first was Bat and Ball
I have inputted into Geany which saves and runs but my issue is that when i run the file in geany it opens my LXterminal then opens a second window which just gives me a black screen so when i goto close said window it shows me for a few seconds my bat and ball waiting there....then closes down cause i hit the x button a couple seconds before.
Any ideas why it runs but just shows me a black screen (what i suspect is the bat and ball are behind this)
Help!

Thanks

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: The Magic Pi problems

Thu Jul 26, 2012 12:05 pm

You don't state which OS you are using, but have you tried running the program from the CLI, ie

python batandball.py


Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

anakinmorgan
Posts: 13
Joined: Wed Jul 18, 2012 6:17 pm

Re: The Magic Pi problems

Thu Jul 26, 2012 1:13 pm

I am running wheezy raspian i think its called its the new one from the website raspberry pi.
I have tried to run from the LXTerminnal
I put in as you said python batandball.py but it comes up with python: cant open file 'batandball.py' error 2 no such file or directory

Thanks

anakinmorgan
Posts: 13
Joined: Wed Jul 18, 2012 6:17 pm

Re: The Magic Pi problems

Thu Jul 26, 2012 1:20 pm

Ok
So this is what i did
I renamed the folder and file to forprograms instead of For_Programs and batandball instead of BatAndBall which LXterminal recognised both and all i did was what you said and typed python batandball.py And it ran which was good
But i have the same issue with the window that came up with the heading Bat and Ball, it again does not allow me to see anything and when i try to put my mouse pointer in it sort of goes to the back of the window.
So its black windown and when i close it it comes to life for two seconds.
Is this a memory issue??

texy
Forum Moderator
Forum Moderator
Posts: 5160
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: The Magic Pi problems

Thu Jul 26, 2012 1:38 pm

anakinmorgan wrote:I am running wheezy raspian i think its called its the new one from the website raspberry pi.
I have tried to run from the LXTerminnal
I put in as you said python batandball.py but it comes up with python: cant open file 'batandball.py' error 2 no such file or directory

Thanks
Thats because it doesn't know where the batandball.py file is. You need to 'cd' to where you have saved it, and try again.

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Justin72
Posts: 11
Joined: Tue Aug 14, 2012 6:49 am

Re: The MagPi problems

Tue Aug 14, 2012 6:50 am

Did you ever get this fixed? I am trying the same tutorial and having the same problem!

Justin

User avatar
GuptaGubbins
Posts: 30
Joined: Fri Jun 22, 2012 9:10 am

Re: The MagPi problems

Tue Aug 14, 2012 3:27 pm

I had the Pygame black screen issue a while back, I also found if I save the .py file in a different location, the standard root directory where it defualts to (I think) it then runs OK..
I will check when I get home tonight and advise on exact path.

antiloquax
Posts: 406
Joined: Sun Nov 20, 2011 11:37 am
Contact: Website

Re: The MagPi problems

Fri Aug 17, 2012 4:11 pm

Sorry to hear you are having problems with Bat and Ball. I wrote that code (although not quite in the form in which it was printed).
You might find it useful to look at two video tutorials I have put together.
This link points at Video 7, in which I talk about Pygame "basics" and then in Video 8 I go through the bat and ball example.
mark

GMT64
Posts: 17
Joined: Sun May 27, 2012 2:46 pm

Re: The MagPi problems

Sat Jun 15, 2013 4:59 pm

Antiloquax,

(sortry this message is so long after your original thread/message, but I've only just got my Pi working ... I'm trying to learn some Linux, some Python and some Java all at the same time (!) so I'm struggling with a few things.)

For Python I've been reading the articles in the Magpi magazine. I got most of the ones in Issue 1 working okay, and with a little bit of effort I got the bat_and-ball one to work 'in a fashion'.

Bat and Ball game ... I just get a black screen with the bat and ball on it, and I can move the bat around and hit the ball. However, I do not have a 'box' showing the name of the game ... the playing field appears to be a black area on a black background - so I have to guess where it will bounce off the wall. I'm running this from the command-line (having typed-in the program using nano). In fact, I had to use 'sudo' to make it work at all, otherwise I get errors.

What am I doing wrong? Why do I not see a 'box' with a title?

Thanks,

GMT64/Graham
London

User avatar
xranby
Posts: 539
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: The MagPi problems

Sat Jun 15, 2013 10:06 pm

GMT64 wrote:...
Bat and Ball game ... I just get a black screen with the bat and ball on it, and I can move the bat around and hit the ball. However, I do not have a 'box' showing the name of the game ... the playing field appears to be a black area on a black background - so I have to guess where it will bounce off the wall. '...
I'm running this from the command-line (having typed-in the program using nano). In fact, I had to use 'sudo' to make it work at all, otherwise I get errors.

What am I doing wrong? Why do I not see a 'box' with a title?
...
You have done all right! What you see this is the expected display output when running the example "Bat and Ball", magpi 1- may 2012 page 28 & 29, game from console on a raspberry pi with display output directed to the Linux "framebuffer".

When you use pygame from the commandline pygame will try open the Linux "framebuffer" this means all output is displayed in full-screen on your primary monitor/tv. "sudo" grants your application access to open this Linux "framebuffer" device.
The "frambuffer" do not have any concept of "windows" therefore you will not get any window-box with a window title; instead pygame will paint the "Bat and Ball" game, with a black background, centred at the middle of the screen, with black borders.

To my knowledge it is not possible to change the pygame border colour while in "framebuffer" mode, instead you can change the games playfield colour to be say blue or yellow by changing the clear statement inside the game main loop
change
screen.fill((0,0,0))
to
screen.fill((0,0,50)) # clears the screen with dark blue
or for example
screen.fill((70,70,0)) # clears the screen with a quite dark yellow
this will make the playfield stand out against the, always black, full-screen frame-buffer border.

The three numbers represent a colour mix of (RED, GREEN, and BLUE) with each colour represented by a number from 0 to 255. Experiment and have fun!

We also need to add a new way to exit the game because we do not have a window close box to click. For fullscreen applications we can make the game exit by pressing the escape key, see below:

The start of the changed main loop with the two suggested changes should then look like this:

Code: Select all

# main game loop
while done == 0:

    screen.fill((70,70,0)) # fill screen with dark yellow

    # event handling
    for event in pygame.event.get(): # if we click something ...
        if event.type == pygame.QUIT: # if we click close ...
            done=1 # this will cause the loop to finish.
        if event.type == KEYDOWN: # if we type something ...
            if event.key == K_ESCAPE: # if we pressed the escape key ...
                done = 1# this will also cause the loop to finish.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

GMT64
Posts: 17
Joined: Sun May 27, 2012 2:46 pm

Re: The MagPi problems

Sun Jun 16, 2013 10:32 pm

xranby,

thanks for the reply ... gives me a little bit more confidence that I was doing the right thing, and moving in the right direction.

Reading some of the other threads on here (and some of the links to YT videos), other users have been using LXDE to create and run their Python programs ... ashamed to say - I never even thought of that!
I got around to trying the Magpi progs under LXDE and they all work as expected, which also helped my confidence. It did, however, throw up a minor problem for me ... un-related to Python, but stopping me using Python under LXDE.

When I start my Pi and enter the user/password as pi/raspberry, I start LXDE and get 8 or 9 icons/programs on the screen along with the large raspberry logo. I can click on the icons and run the programs. All well and good.
However, I don't want to be using the pi/raspberry user ... I have set-up another user for me to use (just my initials, nothing complicated). When I start LXDE I find that I do not have any icons on the screen ... how do I get the icons there if I don't know what they are called, what the 'standard set of programs/icons' are, or which programs the icons should be associated with.

Does anyone else get this? Is it something that I have done wrong? I have not seen any instructions telling me how to set-up LXDE, I just assumed that with my own username I'd get the same stuff as username 'pi'.

Thanks for your advice.

GMT64/Graham
London.

User avatar
paddyg
Posts: 2439
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: The MagPi problems

Mon Jun 17, 2013 7:33 am

If your new user is set up in a standard way I would expect to be able to get application via the little 'start' swallow style menu button. Right click option to put them on the desktop.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

dr_d_gee
Posts: 84
Joined: Fri Jan 04, 2013 1:30 pm

Re: The MagPi problems

Mon Jun 17, 2013 1:10 pm

GMT64 wrote:When I start my Pi and enter the user/password as pi/raspberry, I start LXDE and get 8 or 9 icons/programs on the screen along with the large raspberry logo. I can click on the icons and run the programs. All well and good.
However, I don't want to be using the pi/raspberry user ... I have set-up another user for me to use (just my initials, nothing complicated). When I start LXDE I find that I do not have any icons on the screen ... how do I get the icons there if I don't know what they are called, what the 'standard set of programs/icons' are, or which programs the icons should be associated with.

Does anyone else get this? Is it something that I have done wrong? I have not seen any instructions telling me how to set-up LXDE, I just assumed that with my own username I'd get the same stuff as username 'pi'.

Thanks for your advice.

GMT64/Graham
London.
You need to copy all of the files with the extension '.desktop' from /home/pi/Desktop to your user's Desktop directory. For example (logged in as your new user; you can omit the first line if already in your home directory):

Code: Select all

cd ~
sudo cp /home/pi/Desktop/*.desktop ~/Desktop
You will need to give the password for pi (rather than your new user) when prompted, unless the user you've created has sudo rights.

Return to “Python”