Advertisement

Python Won't Comp

Started by August 07, 2004 05:55 PM
8 comments, last by TravisWells 20 years, 3 months ago
I am having trouble getting the example from pygame.org called "Intro" to compile. I am running the latest version of python and pygame version 1.6. here is the code:

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("ball.bmp")
ballrect = ball.get_rect()

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

	ballrect = 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()


Can anyone help? Edit - Added source box - indentation matters [Edited by - Fruny on August 7, 2004 8:43:30 PM]
Remember who are today and tomarrow will arrive unnoticed.
I don't see why you wold need to compile an example script... but anyway, what kidn of error are you getting?
Advertisement
If you don't post the errors you get, it's much harder for us to derive the error.
if event.type == pygame.QUIT: then what?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
What errors are you egtting? Are you sure you have a ball.bmp in the same directory?
That syntax looks nice. [tears]
Not giving is not stealing.
Advertisement
My workflow might be entirely wrong. What I do is use notepad and save the files as .py, this gives them the proper icon. When I double click on them, they either bring up a dos window in the back and run, or, if it containing errors (I guess thats it) It breifly brings up the same dos window, but only for a moment then It shuts down. Am I not executing this right? I admit, I don't really understand python.
Remember who are today and tomarrow will arrive unnoticed.
That's one way to do it, though I far prefer using IDLE which comes with python. This is a nicer editor than just plain notepad, it comes with a debugger and also a python console so when you run a program you can actually read the error messages python gives.
Looking at the listing here you have mistakes in line 15 and line 17. See them?

Oh and Python is interpreted, not compiled.
Then what are all these "Compiled Python File (.pyc)" files?
(It's compiled to bytecode, which is then run on a VM)

This topic is closed to new replies.

Advertisement