Web Analytics Made Easy - Statcounter
Skip to content

Use the "Net APIs" to Download & Display An Image

PySimpleGUI 5 includes a new set of API calls for networking (Net APIs). There are currently two calls, both download files:

net_download_file and net_download_file_binary

The call net_download_file_binary simply calls net_download_file with the parameters set so that the result is a binary file is downloaded.

In this Cookbook Recipe, we're going to download a PNG file and display it in our Window.

The code is compressed down to only 2 lines. The import, and a line to create and display the Window.

The layout simply has an Image element to display the image.

JPG Example (Requires Conversion to PNG)

As a second example, we're going to download a JPG file and display it in a Window.

Remember the Image elements cannot display JPG files. If you want to show a JPG, you'll need to use the PIL module to convert to PNG. This requires several lines of code that converts from JPG to PNG.