Introduction to Python

Backdrop & Costumes

Lesson 2: Animations

Backdrops and Costumes in Python Mode

Just like in block coding, Python mode in PictoBlox allows you to control backdrops and costumes using code. Instead of dragging blocks, you write Python functions to change how the Stage and sprites look.

PictoBlox interface showing the Backdrops tab on the left with multiple backdrop thumbnails and the Costumes tab showing multiple Tobi costume frames

Controlling Backdrops with Python

The Stage object in PictoBlox has functions to switch between backdrops. You can change the backdrop by name or switch to the next one in sequence.

Backdrop Functions in Python

FunctionWhat it DoesExample
stage.switch_backdrop(name)Switches the Stage to a specific backdrop by namestage.switch_backdrop("Forest")
stage.next_backdrop()Switches to the next backdrop in the liststage.next_backdrop()
stage.backdrop_name()Returns the name of the current backdropprint(stage.backdrop_name())
Two PictoBlox stages side by side — the left shows a plain white backdrop and the right shows a Forest backdrop after running stage.switch_backdrop

Controlling Costumes with Python

Sprites also have functions to switch between their costumes. This is the key to creating animations in Python!

A horizontal strip showing four Tobi costumes in sequence — Tobi, Tobi Walking 1, Tobi Walking 2, and Tobi mouth open — illustrating costume frames

Costume Functions in Python

FunctionWhat it DoesExample
sprite.switch_costume(name)Switches the sprite to a specific costume by nametobi.switch_costume("Tobi Walking 1")
sprite.next_costume()Switches to the next costume in the listtobi.next_costume()
sprite.costume_name()Returns the name of the current costumeprint(tobi.costume_name())
Costume and backdrop names are case-sensitive in Python. Make sure the name you use in your code matches exactly with the name shown in the Costumes or Backdrops tab!

Example: Changing the Backdrop

# Switch to the Forest backdrop stage.switch_backdrop("Forest") # Print the current backdrop name print(stage.backdrop_name())

Subscribe to our newsletter.

Get updates to news and events.