Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Drawing on the Screen

In this lesson, you’ll start drawing on the screen using a Surface. Recall that a Surface is a rectangular object on which you can draw, like a blank sheet of paper. The screen object is a Surface, and you can create your own Surface objects separate from the display screen.

You’ll fill the screen with white, and add a new Surface object to display on the screen. Add the code below your existing code, starting at line 44. Note the indentation, keeping the lines you are adding within the game loop, but outside the event loop:

44 # Fill the screen with white
45 screen.fill((255, 255, 255))
46 
47 # Create a surface and pass in a tuple containing its length and width
48 surf = pygame.Surface((50, 50))
49 
50 # Give the surface a color to separate it from the background
51 surf.fill((0, 0, 0))
52 rect = surf.get_rect()

For more information about the Surface and Rect classes, check out the following resources from the pygame documentation:

Comments & Discussion

Become a Member to join the conversation.