PySimpleGUI Tutorial
Selected Reading
- PySimpleGUI - Discussion
- PySimpleGUI - Useful Resources
- PySimpleGUI - Quick Guide
- PySimpleGUI - Settings
- PySimpleGUI - Debugger
- PySimpleGUI - Working with PIL
- PySimpleGUI - Matplotlib Integration
- PySimpleGUI - Menubar
- PySimpleGUI - Events
- PySimpleGUI - Element Class
- PySimpleGUI - Window Class
- PySimpleGUI - Popup Windows
- PySimpleGUI - Hello World
- PySimpleGUI - Environment Setup
- PySimpleGUI - Introduction
- PySimpleGUI - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PySimpleGUI - Working with PIL
PySimpleGUI - Working with PIL
Python Imaging Library is a free, cross-platform and open-source pbrary for the Python programming language that has the functionapty for opening, manipulating, and saving many different image file formats.
To install it, use the PIP command as follows −
pip3 install pillow
In the following example, we obtain the byte value of the PNG image with PIL function and display the same in Image element on a PySimpleGUI window.
import PySimpleGUI as sg import PIL.Image import io import base64 def convert_to_bytes(file_or_bytes, resize=None): img = PIL.Image.open(file_or_bytes) with io.BytesIO() as bio: img.save(bio, format="PNG") del img return bio.getvalue() imgdata = convert_to_bytes("PySimpleGUI_logo.png") layout = [[sg.Image(key= -IMAGE- , data=imgdata)]] window = sg.Window( PIL based Image Viewer , layout,resizable=True) while True: event, values = window.read() if event == sg.WIN_CLOSED: break window.close()
It will produce the following output window −
Advertisements