Adam Fitch wrote:
Hello,
Hi!
First, I downloaded and installed Python itself, version 2.4.4 (the
"python-2.4.4.msi" file), from python.org <http://python.org>.
Good so far.
Second, I downloaded and ran the "pygame-1.7.1release.win32-py2.4.exe
" file.
Yep, that's what you should do.
Third, I downloaded the "pygame-1.7.1release.zip" file. However, I'm
not sure where to extract this file to, and it looks like the
"art assets" I need are there in the
"pygame-1.7.1release\examples\data\ " directory.
Yes. Basically what you're probably interested in are the \examples and
the \docs directories. the rest of the stuff in that zip is just source,
which you don't need because you installed pygame already.
So anyway, from the tutorial (Lecture 3 at
http://rene.f0o.com/mywiki/LectureThree), I typed the following into
the Python command line:
>>> import pygame, sys,os
>>> from pygame.locals import *
>>> pygame.init()
(6, 0)
>>> window = pygame.display.set_mode((468, 60))
>>> pygame.display.set_caption ('Monkey Fever')
>>> screen = pygame.display.get_surface()
>>> monkey_head_file_name = os.path.join("data","chimp.bmp")
>>> print monkey_head_file_name
data\chimp.bmp
>>> monkey_surface = pygame.image.load(monkey_head_file_name)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pygame.error: Couldn't open data\chimp.bmp
>>> screen.blit(monkey_surface, (0,0))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'monkey_surface' is not defined
Now, obviously, I know why this failed; 'monkey_surface' is not
defined, because it failed to define itself in the "monkey_surface =
pygame.image.load(monkey_head_file_name)" line. Pygame couldn't open
the "chimp.bmp" file. The question is, where *should* this file be
located, and why isn't it in the "C:\\Program
Files\Pygame-Docs\examples\" directory, as it says it should be in the
tutorial? Pygame isn't creating a directory called "C:\\Program
Files\Pygame-Docs\examples\", and it looks like the stuff I need is in
the " pygame-1.7.1release.zip" file; it seems like all I need to do
is figure out where to put that data so that Pygame will recognize it.
Python searches a certain number of directories when it is looking for
files. generally, it searches the current working directory first.
So one way you could solve this is from running your python program from
a certain directory.
for example, i create the directory 'c:\pygame\data\' with the file
'test.bmp' in it (which is a jpg... just kidding)
Then I start a cmd window by going to start > run, typing cmd, and
hitting enter.
i issue the command 'cd c:\pygame'
Then I type 'python', which runs the interactive interpreter.
(If this doesn't work, type 'path = %path%;c:\python24' and try the
command again.
this sets your path to be the same as it was before (%path%) with the
addition of your python directory.)
now we can check our current directory:
>>> print os.getcwd()
C:\pygame
you should be able to do everything from here.
>>> pygame.image.load('data\\test.bmp')
<Surface(160x120x24 SW)>
There are other ways to do this, but this is the way i would do it.
If you included the data somewhere else on the pypath, then someday you
might be trying to load 'test.bmp' and not realize you named it
'tset.bmp' on accident and it now is loading some image you don't want
it to.
As a side note, the Pygame window doesn't seem to be initializing
correctly; it just stays black, and when I mouseover it, I get the
"hourglass" icon from Windows.
Pygame needs calls to its display.update() method as well as clearing
out the input queue to keep this from happening. You'll get to that
later in the tutorial.
Try running examples\chimp.py if you want to make sure pygame is working.
Anyway, thanks for any help anyone can provide, and, again, I'm sorry
to be asking such simple questions, but I've tried for a week to work
out what's gone wrong myself, and it seems better to ask the
professionals at this point. :-)
I think you made the right choice :)
By the way, if you are just getting into Python, you might want to look
into joining the tutor mailing list also.
There are lots of friendly and knowledgeable people who hang out on that
list.
Hope to see you there, and be sure to update us on your progress.
You'll probably get some other e-mails detailing other ways to do this
as well.
Thanks,
-Adam
You're welcome.
-Luke