Easily use JPGs, GIF, ICO, WebP, PNG files/images with PySimpleGUI.
Not sure what to call this thing exactly so I'm going with Expansion Package. It's an add-on that adds to PySimpleGUI without requiring PySimpleGUI to make any changes.
set of functions that fit with PySimpleGUI's parameters for working with images, like the Base64 encoded PNG format. Where you would normally have a base64png or filename in a PySimpleGUI Element, you can now use a JPG, ICO, etc, by converting and resizing the image and returing it in a format that can be directly passed into PySimpleGUI Elements.
You need to only change one parameter in your code, and the change is to wrap it in a function call.
import PySimpleGUI as sg
from psg_pillow import convert_image
my_jpg = r'my_image.jpg'
layout = [[sg.Image(convert_image(my_jpg))],
[sg.Image(convert_image(my_jpg, resize_w_h=(150,150)))]]
window = sg.Window('psg_pillow Image Test', layout)
window.read()Resizing is as easy as adding a parameter to the convert_image call. It's meant to provide a simple, minimal code API for integrating images into PySimpleGUI.
I've found using icons that are downloaded from the web can be a multi-step process, particularly if you want colors to match. Here's a PNG icon I downloaded. It's got black lines and a transparent alpha channel.
It doesn't work so well on dark backgrounds. That's a simple operation, an additional parameter to the convert call. This program displays the image unchanged, as an image with the color changed to white and as a button with the color changed to match the theme.
import PySimpleGUI as sg
from psg_pillow import convert_image
octogon = b'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAATlBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADEoqZZAAAAGXRSTlMAgARwq6y3pvigh+AZdUw0LSLs0paMOMBcGua82AAAAKZJREFUeJx10ukSgyAMBOAYkEO0nj32/V+005rU2MH8gv3GZWQg+o5LkEluTyRHaGQCjDi0rGtuD7E5GdH85vPDyqA5SklG7oh7T1iZl03bOkKU7rASlSybCEIj6wb9hNdvc8CMYUtcAQpl0aYz3ICxClSeVIe+v4BprkMGOgv6gyO6DCnjiONKDLD/fDvA7xK1iv1+vU5FDtfcyF9+FptfP4ba83kDfWMLa9w3G1EAAAAASUVORK5CYII='
K_IMAGE = '-IMAGE-'
sg.theme('darkred')
layout = [ [sg.Image(octogon)],
[sg.Image(source=convert_image(octogon, change_to_color='#FFFFFF', color_change_is_luminance=False, resize_percent=3))],
[sg.Button(image_source=convert_image(octogon, change_to_color='#F9D276', color_change_is_luminance=False, resize_percent=3), k='Exit')] ]
window = sg.Window('psg_pillow Image Test', layout)
event, values = window.read()
NOTE - psg_pillow has not been uploaded to PyPI yet. Soon. For now, use this GitHub copy.
The GitHub repo has the most up-to-date code. You can install directly without cloning:
python -m pip install --upgrade https://github.com/PySimpleGUI/psg_pillow/zipball/masterOr clone/download the repo and install locally:
python -m pip install .PySimpleGUI has always been developed more like a proprietary product than an open source project. Pull requests aren't accepted.
Copyright 2018-2026 PySimpleGUI. All rights reserved.
Licensed under LGPL3.
