I'm trying to set an image as a background with Tkinter. I'm doing this by using a label with an image and at first, it worked fine. However, when I try to do the same thing within a function that creates a new window all I get is an empty (all white) image.
This is the code that doesn't work:
def myWardrobeWindow():
wardrobeWindow = tk.Toplevel(root)
wardrobeWindow.title("My Wardrobe")
wardrobeWindow.geometry("800x800")
wardrobeBackgroundImage = tk.PhotoImage(file='simpleWallpaper3.png')
wardrobeBackgroundLabel = tk.Label(wardrobeWindow, image=wardrobeBackgroundImage)
wardrobeBackgroundLabel.pack()
And this is the code that does work:
root = tk.Tk()
root.resizable(width=False, height=False)
canvas = tk.Canvas(root, height=700, width=700)
canvas.pack()
backgroundImage = tk.PhotoImage(file='simpleWallpaper3.png')
backgroundLabel = tk.Label(root, image=backgroundImage)
backgroundLabel.place(relx=0, rely=0, relheight=1, relwidth=1)