Reputation: 91
I have just started working with the PySimpleGUI framework with the Tkinter port and I don't understand how an image can be inserted as a background for a window in a program.
There is no argument or parameter associated with adding a background image for the Window component.
My code:
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()
Upvotes: 4
Views: 8425
Reputation: 487
In the latest version of PySimpleGUI, it's very simple. If you look at the screenshots on PySimpleGUI website https://pysimplegui.readthedocs.io/en/latest/screenshots_demos/ you will see a window with the Milky Way Galaxy set as the background.
Here is the code on how to do it. https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Window_Background_Image.py
However, the code embeds the image data into the file. I prefer not to do it that way. I prefer to just call it by the filename. If you prefer to do it that way too, just change:
background_layout = [ title_bar('This is the titlebar', sg.theme_text_color(), sg.theme_background_color()), [sg.Image(data=background_image)]]
and remove background_image = b'...
at the bottom of the file
to
background_layout = [title_bar('This is the titlebar', sg.theme_text_color(), sg.theme_background_color()), [sg.Image(r'background.png')]]
Hope that helps :)
Upvotes: 1