When I click the button to change the image, the window refresh does not work. I don't know how to implement it properly. How can I refresh the api with the button. I'm new to pysimplegui; can somebody point me in the correct direction?
from io import BytesIO
import PySimpleGUI as sg
from PIL import Image
import requests, json
def image_to_data(im):
with BytesIO() as output:
im.save(output, format="PNG")
data = output.getvalue()
return data
cutURL = 'https://meme-api.herokuapp.com/gimme/wholesomememes'
imageURL = json.loads(requests.get(cutURL).content)["url"]
data = requests.get(imageURL).content
stream = BytesIO(data)
img = Image.open(stream)
giy=image_to_data(img)
control_col = sg.Column([
[sg.Button('next meme', key = '_3_')],])
image_col = sg.Column([[sg.Image(giy, key = '-IMAGE-')]])
layout = [[control_col,image_col]]
window = sg.Window('meme', layout,finalize=True)
while True:
event, values = window.read()
if event is None:
break
if '_3_' in event:
window.refresh()
window.close()