Before coding anything you're supposed to download two images and a sound file, all of which I've done. You then use IDLE to create a .py file in the same folder with the downloads. They feed it to you a bit at a time along with explanatory text. In the following code the pygame.quit() instruction marks the end of what they give you in stage one; they tell you that this will produce a black screen momentarily which then disappears when it reaches the pygame.quit() instruction. That worked for me as expected.
Then they give you four more lines to display the image plus a sleep. Here's what it looks like at that point, and where (at least in my case) the problem arises:
Theoretically that should display the image for 3 seconds and then terminate. What happens for me is I get the black graphics mode screen with a mouse cursor, which responds when I move the mouse, but nothing else. And it hangs there indefinitely. I tried lots of key combinations, starting with Ctrl-C, Ctrl-Q, Ctrl-Z, etc. with no apparent effect.
Code: Select all
import pygame from pygame.locals import* from time import sleep from random import randrange pygame.init() width = pygame.display.Info().current_w height = pygame.display.Info().current_h screen = pygame.display.set_mode((width, height), FULLSCREEN) #with the following uncommented, the program terminates as expected #pygame.quit() difference = pygame.image.load('spot_the_difference.jpg') difference = pygame.transform.scale(difference, (width, height)) screen.blit(difference, (0, 0)) pygame.display.update() sleep(3) pygame.quit()
Eventually I got on another computer and learned while googling (I'm new to the Raspian OS) that I could open another terminal by using Ctrl-Alt-F2. The same place I found that suggested a "sudo killall", but that didn't work for me - switching back to the initial terminal via Ctrl-Alt-F7 I still had the black screen and cursor. In the end I bailed by issuing a "sudo shudown".
Basically I'm assuming that others are running this successfully and why it isn't working for me. I'm new to Python as well as to the Raspberry Pi, but have a lot of experience with C/C++ code. I'd very much like to understand what's going on beyond the obvious that I'm in graphics mode and hanging. I'd expect the program to terminate with an error code, or give me a pop-up notification, or something. If you have ideas for me, I'd appreciate hearing them.
I did a sudo update yesterday before starting this project. I'm using Python 3.4.2 on a RaspberryPi 3 which is running Linux version 4.4.21-v7+.