repl.it
@PySimpleGUI/

PySimpleGUIWeb finalization issue

Python

Image data isn't updated despite finalize=True and .finalize()

fork
loading
Files
  • main.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Demonstration of PySimpleGUI issue #2507
# See https://github.com/PySimpleGUI/PySimpleGUI/issues/2507

from io import BytesIO
from PIL import Image
import PySimpleGUIWeb as sg

def create_image():
    file = BytesIO()
    image = Image.new('RGB', size=(300, 380), color='red')
    image.save(file, 'png')
    file.name = 'image.png'
    file.seek(0)
    return file

image_data = create_image().read()

print(sg.version, sg)

layout = [[sg.Image(key='-IMAGE-')],
          [sg.Button('Refresh', key='-REFRESH-'), sg.Exit()]]

window = sg.Window('Image Update Issue', layout, finalize=True)
window.finalize()
window['-IMAGE-'].update(data=image_data)

while True:
    event, values = window.read()
    if event in (None, 'Exit'):
        break
    elif event == '-REFRESH-':
        window['-IMAGE-'].update(data=image_data)
Fetching token
?