繁体   English   中英

在 PySimpleGUI window 中插入图像作为背景

[英]Inserting an image as background in PySimpleGUI window

我刚刚开始使用带有 Tkinter 端口的 PySimpleGUI 框架,我不明白如何在程序中插入图像作为 window 的背景。

没有与为 Window 组件添加背景图像相关的参数或参数。

我的代码:

import PySimpleGUI as sg
        
layout1 = [[sg.Text("What File Type do you want to generate?")],
           [sg.Checkbox("PowerPoint Presentation", auto_size_text=True)],
           [sg.Checkbox("PDF", auto_size_text=True)]]
        
window = sg.Window("Demo", layout1)
        
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:
        break
        
window.close()

在最新版本的 PySimpleGUI 中,它非常简单。 如果您查看 PySimpleGUI 网站https://pysimplegui.readthedocs.io/en/latest/screenshots_demos/上的屏幕截图,您将看到 window 以银河系为背景。

这是有关如何执行此操作的代码。 https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Window_Background_Image.py

但是,代码将图像数据嵌入到文件中。 我不喜欢那样做。 我更喜欢只用文件名来称呼它。 如果您也喜欢这样做,只需更改:
background_layout = [ title_bar('This is the titlebar', sg.theme_text_color(), sg.theme_background_color()), [sg.Image(data=background_image)]]
并删除文件底部的background_image = b'...

background_layout = [title_bar('This is the titlebar', sg.theme_text_color(), sg.theme_background_color()), [sg.Image(r'background.png')]]

希望有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM