سؤال

I was running a simple python file:

from livewires import games

games.init(screen_width = 640, screen_height = 480, fps = 50)

games.screen.mainloop()

When I run this in IDLE, I get the error printed in the title. I copy and pasted this code from a book. I'm at the early stages of a beginner, so I don't know much. I'm fairly sure that I installed livewires properly as i've already run other programs with its modules. (gosh, I know that that is probably not the right terminology at all, sorry.) I'm not exactly looking for a way to fix this, (although that'd be nice, too) I'm just hoping someone could explain exactly what the problem is. I copied the code from a book so I don't understand what I did wrong. I'm 100% positive that there are no typos, too.

هل كانت مفيدة؟

المحلول

Well, searching around, it seems that this is the livewires website: Livewires Home Page where one can download their livewires package.

Also, some code from this: Chapter 11 looks like what he's posted here ("The Pizza Panic Game").

Downloading and unpacking livewires shows that there is indeed no init function in the games module (as the comments already mentioned).

Either this book has non-working examples (doubtful, given the depth it explains this example with); or the livewires package has changed between when the book was written and now (much more likely).

The livewires website has other examples on it which I think you'll have much more success with.
I'd recommend you ditch the book, since it's likely you'll keep running into roadblocks like this. A Google search will turn up a number of other free python tutorials which are more up-to-date, and will be easier to follow.

This page has a few links for beginners: Beginners Guide

نصائح أخرى

An older version of livewires that works with the code from "Python Programming for the Absolute Beginner " can be downloaded from the book companion website :

http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002

I just started with the same book, Python Programming Third Ed. by Michael Dawson, and ran into the same problem. It has changed since the book was written.

If you still wanted to create the window here is the code that I used and it works:

from livewires import games

#This is the code M. Dawson has in the book
#games.init(screen_width = 640, screen_height = 480, fps = 50)
#games.screen.mainloop()

my_screen = games.Screen(width = 640, height = 480)
my_screen.mainloop(fps = 50)

The screen is now treated as an object to be instantiated. The Screen class no longer accepts fps in its constructor, now pass that fps into the mainloop method. If you do not pass fps into mainloop method, it will default to 50.

I had the same problem then I downloaded the code from slejdops' site he linked to. Sounds like the creator of it is open to the idea of getting it like this cause they always keep this stuff on lock down with text books. That makes it both ok and legal. :)

So go here. Have fun and good luck: http://www.delmarlearning.com/companions/content/1435455002/downloads/index.asp?isbn=1435455002

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top