The Screen Object
While the pygame API and documentation is quite clear (see the pygame.draw documentation, for example), most of the pygame drawing operations take place on a screen, which is rendered on a specific display.The way that the code we entered in the previous page works is it initializes the display in the __init__ function, and it then allows us to access a field named 'screen', where all of the actual drawing and graphics work is done in pygame (you pass a reference to this screen to most drawing functions).
You can see how this works by looking at the 'test' function we added and called:
# Fill the screen with red (255, 0, 0) red = (255, 0, 0) self.screen.fill(red) # Update the display pygame.display.update()
pygame.display.update()
Accessing the Screen
Since we made a wrapper class called pyscope which takes care of the low-level framebuffer initialisation, etc., how do you access the screen object from outside the class? It's easy ... any time you want to do any drawing, you just need to access the screen as follows:# Create an instance of the PyScope class scope = pyscope() # Fill the screen with yellow scope.screen.fill((255, 255, 0)) # Update the display pygame.display.update() # Wait 10 seconds time.sleep(10)