How to add multimedia in pyleap – image, audio, and text



Table of Contents

Image

To insert an image we have to use the Sprite method.

Syntax:

Sprite(url, x=window.center, y=window.center)

# OR

Sprite("image location/image name.jpg", 300, 300)

url = file path or url of the Sprite (image format should be specified)
x = x-coordinate of the center of the sprite
y = y-coordinate of the center of the sprite

Text

Syntax:

Text(src, x=window.center, y=window.center, font_size=16, color= “orange”, font_name=None )

# OR

Text("Welcome to pyleap", 200, 200, 24, "blue", ""times new roman")

src = Text content
x, y = position of the bottom left corner of the text
font-size = text_size
color = text color
font_name = font



Audio

The audio formats supported by pyleap are AU, MP2, MP3, OGG / Vorbis, WAV, WMA …

Syntax:

Audio(url, loop=True)

# OR

Audio("song.mp4", loop=True)

Two methods that we can use with the audio method:

  1. play() – plays the audio
  2. pause() – stops the audio

Your system should have AVBIN installed so that audio() works without an error. Watch a video on how to install AVbin.



The Audio method needs to have loop=True to avoid being repeated along with the Draw function. If the program requires an event to trigger the playing of the song only once, then the loop can be False.