I am working on a simple application using PySimpleGUI that shows a gif character in an "idle" animation and want to be able to change to a different gif animation when hitting a button, have the animation play for 5 seconds, then automatically switch back to the "idle" animation. I have been able to complete all of the above aside from the "play for 5 seconds, then automatically switch back to the 'idle' animation" piece.
Here is the code thus far:
import PySimpleGUI as sg
# storing gifs as base64
idle = b'[base64 encoded gif]'
wave = b'[base64 encoded gif]'
cheer = b'[base64 encoded gif]'
tipjar = b'[base64 encoded gif]'
cocktail = b'[base64 encoded gif]'
beer = b'[base64 encoded gif]'
# Putting all gifs into a list
gifs = [idle, wave, cheer, tipjar, cocktail, beer]
# Setting up the window and button layout
sg.theme('DarkAmber')
layout = [[sg.Image(background_color='#00b140', key='-IMAGE-', pad=(0, 0), right_click_menu=[
'&Right', ['Settings', 'Exit']])],
[sg.Button('!Wave'), sg.Button('!Cheer'), sg.Button('!TipJar'), sg.Button('!Cocktail'), sg.Button('!Beer')]]
window = sg.Window('Animated Avatar', layout, margins=(0, 0), finalize=True)
image = window['-IMAGE-']
# Calling the first item in the gifs list
gif = gifs[0]
# Program loop
while True:
event, values = window.read(timeout=100)
if event == sg.WIN_CLOSED or event == 'Exit':
break
# Button click events to change the gif being presented
elif event == '!Wave':
gif = gifs[1]
elif event == '!Cheer':
gif = gifs[2]
elif event == '!TipJar':
gif = gifs[3]
elif event == '!Cocktail':
gif = gifs[4]
elif event == '!Beer':
gif = gifs[5]
# Overall gif animation rules
image.update_animation(gif, 500)
How can I complete the 5 second gif animation and return to idle?
