How to add multimedia in pyleap – image, audio, and text
To insert an image we have to use the Sprite method.
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(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
The audio formats supported by pyleap are AU, MP2, MP3, OGG / Vorbis, WAV, WMA …
Audio(url, loop=True) # OR Audio("song.mp4", loop=True)
Two methods that we can use with the audio method:
- play() – plays the audio
- 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.