?
Solved

Pygame.org example crashes? Why?

Posted on 2014-01-22
12
Medium Priority
?
252 Views
Last Modified: 2014-03-16
Hi
This Python PyGame intro code from pygame.org crashes

I can't see why

This the source website.

here

and below is the code that causes an "unexpected error"
Why?
Thanks
       
    import sys, pygame
    pygame.init()
 
    size = width, height = 320, 240
    speed = [2, 2]
    black = 0, 0, 0
 
    screen = pygame.display.set_mode(size)
 
    ball = pygame.image.load("http://www.pygame.org/docs/tut/intro/ball.gif")
    ballrect = ball.get_rect()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()

        ballrect = ballrect.move(speed)
        if ballrect.left < 0 or ballrect.right > width:
            speed[0] = -speed[0]
        if ballrect.top < 0 or ballrect.bottom > height:
            speed[1] = -speed[1]

        screen.fill(black)
        screen.blit(ball, ballrect)
        pygame.display.flip()

Open in new window

0
Comment
Question by:beavoid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
12 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 39808862
At a guess,

ball = pygame.image.load("http://www.pygame.org/docs/tut/intro/ball.gif")

is causing the problems; most likely because that image cannot be downloaded (although it does exist),  meaning

ballrect = ball.get_rect()

will explode as "ball" has no image in it.

Can you step through the code in the debugger?
0
 

Author Comment

by:beavoid
ID: 39809653
The debugging system isn't blatantly obvious, like eclipse, for example.

There aren't any 'breakpoint' entries in the menus. How is it done?
Thanks
0
 

Author Comment

by:beavoid
ID: 39809694
Thx
If I left out an attempt to find the file in a path and just had ball.jpg as an argument, where would it look for the file, online and on a file system? wherever the .py file is?

Also, I thought that python was runnable from a webpage, like a Java applet, but it has to be downloaded and then run?

How, where are these games run on this pygame page?

here

How are they stored, in a zip?
?

Thanks
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 19

Expert Comment

by:mrwad99
ID: 39810038
I would assume that it will look in the directory relative to the source file for the image.

What IDE are you using to develop in?
0
 

Author Comment

by:beavoid
ID: 39810100
I'm using IDLE
It launches a Python 3.3.3 shell

how does it know what source to look in? all my recent Java games linked to graphics files in my webspace. My first Java RTS had the image files in a subfolder of the game's disk location.
thx
0
 

Author Comment

by:beavoid
ID: 39931855
I've requested that this question be deleted for the following reason:

Th mods suggested I delete this.
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 2000 total points
ID: 39931828
Sorry about the delay in getting back to you!

I tried this code in Python 2.7.3 with IDLE.  I too found that it fails to load the image when fetched from online (I don't yet know why this is).  I changed it to load the image locally (in answer to your earlier question: it fetches the image from relative to the source file), and it worked fine.  I have attached the images showing this working; please let me know if you still have difficulties.

Again, sorry about the delay.

Code
Running
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 39931856
<Cancelling delete request so beavoid has chance to read my answer before it gets deleted!>
0
 

Author Closing Comment

by:beavoid
ID: 39931944
m99, I appreciate your tenacity, thanks
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 39932949
Glad to help.  

Oh, and I almost forgot: regarding breakpoints, you set them via a right click in the editor; the line with the breakpoint on is highlighted in yellow.  Then, with the debugger open, you choose Run Module (or hit F5), then "Go" in the debugger dialog to continue from line 1 up to your chosen breakpoint position :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question