How to do it...

Create the following script, scroller.py:

  1. Begin by importing the required libraries and parameters:
#!/usr/bin/python3 
# scroller.py 
import tkinter as TK 
import time 
import math 
from random import randint 
 
STEP=7 
xVAL,yVAL=0,1 
MAX_WIDTH,MAX_HEIGHT=640,480 
SPACE_WIDTH=MAX_WIDTH*2 
SPACE_HEIGHT=MAX_HEIGHT*2 
LEFT,UP,RIGHT,DOWN=0,1,2,3 
SPACE_LIMITS=[0,0,SPACE_WIDTH-MAX_WIDTH, 
              SPACE_HEIGHT-MAX_HEIGHT] 
DIS_LIMITS=[STEP,STEP,MAX_WIDTH-STEP,MAX_HEIGHT-STEP] 
BGN_IMG="bg.gif" 
PLAYER_IMG=["playerL.gif","playerU.gif", 
            "playerR.gif","playerD.gif"] 
WALL_IMG=["wallH.gif","wallV.gif"] 
GOLD_IMG="gold.gif" 
MARK_IMG="mark.gif" 
newGame=False 
checks=list() 
  1. Provide functions to handle the movements of the player:
def move_right(event): movePlayer(RIGHT,STEP) ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.