Untitled
unknown
python
2 years ago
653 B
15
Indexable
import PySimpleGUI as sg
from PIL import Image
import io
# Load the image using PIL
image = Image.open("cat.jpg")
image.thumbnail((400, 400)) # Resize the image if needed
# Convert the image to bytes
img_byte_array = io.BytesIO()
image.save(img_byte_array, format="PNG")
img_byte_array = img_byte_array.getvalue()
# Define the layout of the window
layout = [
[sg.Image(data=img_byte_array)],
[sg.Button('Exit')]
]
# Create the window
window = sg.Window('Image Viewer', layout)
# Event loop
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Exit':
break
# Close the window
window.close()
Editor is loading...
Leave a Comment