问题:使用字典中的PNG文件在PySimpleGUI(Python)的“图像”小部件中显示
git log --merges --since="since last week"
定义为:
class Image
您可以这样做:
class Image(Element):
def __init__(self,filename=None,data=None,...):
"""
:param filename: (str) image filename if there is a button image.
GIFs and PNGs only.
:param data: Union[bytes,str] Raw or Base64 representation of the image
to put on button.
Choose either filename or data
类似的事情应该起作用(假设有两个图像:import PySimpleGUI as sg
import os
cwd = os.getcwd()
fname = 'image1.png'
with open('{}/{}'.format(cwd,fname)) as fh:
image1 = fh.read()
[sg.Image(data=image1,key='key1',size=(5,6))]
):
image1,image2
,
PySimpleGUI GitHub上列出的演示程序之一是Demo_Img_Viewer.py。在其中,您将找到一个函数,该函数采用文件名并返回可以传递给update
元素的Image
方法的数据。
此功能是该演示的一部分。它将文件呈现为update方法期望的格式。
from PIL import Image
def get_img_data(f,maxsize=(1200,850)):
"""
Generate image data using PIL
"""
img = Image.open(f)
img.thumbnail(maxsize)
bio = io.BytesIO()
img.save(bio,format="PNG")
del img
return bio.getvalue()
您可以遍历文件并通过调用此函数并保存结果来“预渲染”它们。
然后,您可以使用这些预渲染图像之一更新图像元素。
window['My Image Element Key'].update(data=rendered)
本文链接:https://www.f2er.com/3167139.html