Removed pyperclip in the base64 single image encoding. Forgot to remove when the clipboard functions were added back in release 4.44.0. Changed docstring for clipboard_set to take bytes as well as string

This commit is contained in:
PySimpleGUI 2021-09-07 15:37:03 -04:00
parent 2c9246ad21
commit 3eea8e3a97
2 changed files with 12 additions and 7 deletions

View file

@ -1,13 +1,13 @@
import PySimpleGUI as sg
import base64
import pyperclip
"""
Make base64 image from a file
This is usually done in order to create a Base64 image for use as an Ucon or a Button image
To use, either copy and paste the full path to the file or use the browse button to locate the file.
Once chosen, the conversion will happen automatically with the result placed on the clipboard.
When complete, a popup window is shown that automatically closes after 1 second so you aren't bothered with having to close it
When complete, a popup window is shown that tells you to paste the image before closing the window. This is because of a
tkinter problem on Linux. On Windows you can close the Window, but on Linux, you'll need to keep it open until the paste completes
NOTE - if you're replacing your ICO file for your window with a base64 image, you will first need to convert your icon from
an ICO file into a PNG file. Encode the PNG file and then you'll be able to pass that value in your call to Window:
@ -18,6 +18,8 @@ import pyperclip
Input: a single image file
Output: clipboard will contain the Base64 Byte String of the source image
Copyright 2021 PySimpleGUI
"""
@ -25,8 +27,9 @@ def convert_file_to_base64(filename):
try:
contents = open(filename, 'rb').read()
encoded = base64.b64encode(contents)
pyperclip.copy(str(encoded))
sg.popup('Copied to your clipboard!', auto_close=True, auto_close_duration=1)
sg.clipboard_set(encoded)
# pyperclip.copy(str(encoded))
sg.popup('Copied to your clipboard!', 'Keep window open until you have pasted the base64 bytestring')
except Exception as error:
sg.popup_error('Cancelled - An error occurred', error)