Merge pull request #6067 from PySimpleGUI/Dev-latest

New Demo Program - Display an image located at URL online (thanks to …
This commit is contained in:
PySimpleGUI 2022-11-30 08:46:55 -05:00 committed by GitHub
commit 98140066fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
import PySimpleGUI as sg
import urllib.request
import base64
"""
Display an Image Located at a URL
Downloads and displays a PNG (or GIF) image given a URL
NOTE:
Early versions of tkinter (for example 8.6.6 found in Python 3.6) have trouble with some PNG formats.
Moving to Python 3.7 fixes this or you can use a tool to re-encode the image (e.g. psgresizer) save it and
it will then work OK in Python 3.6.
Example of one of these images - https://www.python.org/static/community_logos/python-logo-master-v3-TM.png
Copyright 2022 PySimpleGUI.org
"""
image_URL = r'https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png'
layout = [[sg.Image(base64.b64encode(urllib.request.urlopen(image_URL).read()))]]
window = sg.Window('Image From URL', layout)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Exit':
break
window.close()