4

I've been coding for a long time but am working my way through a beginner Python book to get acclimated to the syntax. I've worked through some serious obstacles getting pygame installed and have encountered an insurmountable problem. This simple program will display a window, but the background image will not show up:

#game.py
from livewires import games

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

wall_image = games.load_image("wall.jpg", transparent = False)
games.screen.background = wall_image

games.screen.mainloop()

I've checked triple-checked that the wall.jpg file exists and is valid. It is and lives in the same folder as the python file game.py.

There are no errors. The pygame import seems to work find and reports the following message to stdout:

pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html

I'm running this with python 2.7.15, which is AFAIK the default/native python that runs on OSX Mojave. I tried running it with python 3.7, but livewires is apparently not compatible with that version of python.

Can anyone tell me how to fix this? I'd love to just get it working so I can grind thru the rest of this book.

NOTE: the book says it uses a modified version of livewires (which also looks fairly old now that I look at it). I'm not sure what the ettiquette is for sharing files here, so I won't try to post a zip or anything. You should be able to create a livewires sub-folder in the same folder where you've store game.py and put these four files in it:

__init__.py

beginners.py

color.py

games.py

EDIT: This code works fine on my Ubuntu desktop when I set the code up with PyCharm. This environment has python 2.7.6, pygame 1.9.4, the livewires code I've specified here.

The problem appears to be specific to pygame running on OSX mojave, but in the comments @Lau-Real says it works on his OSX-Mojave machine.

13
  • can u run the code u uploaded? I tried to debug ur code and got an error: AttributeError: 'module' object has no attribute 'init'
    – Lau Real
    Jan 22, 2019 at 7:04
  • @LauReal yes! As I describe in the OP, the code runs without a single error, outputs the pygame message to stdout, and shows a window, but the window does not show the background image I've specified. I edited the post to include links to the livewire source, which may make a difference?
    – S. Imp
    Jan 22, 2019 at 7:25
  • Yes, now I can run ur code, and, it's working.
    – Lau Real
    Jan 22, 2019 at 7:40
  • So you see a window and the jpeg image is properly loaded? What OS are you running? What version of python? What version of pygame?
    – S. Imp
    Jan 22, 2019 at 7:42
  • 1
    @Marin unlike Lau-Real, I was not able to get it working on my MacBook at all. It does seem to work just fine on my Ubuntu workstation, so I have been able to proceed with my project on that machine without trouble.
    – S. Imp
    Feb 12, 2019 at 19:52

0