import tkinter as tk
from tkinter import ttk
def picture():
window2 = tk.Toplevel()
window2.title("Window2")
window2.geometry("300x300")
window2.configure(background='grey')
f = "C:\\Users\\Bob\\Documents\\Python\\bb.gif"
img = tk.PhotoImage(file =f)
panel = ttk.Label(window2, width= 100, background = "green", image =img)
panel.grid(column=1, row=1, sticky=(tk.W,tk.E))
#Start the GUI
window = tk.Tk()
window.title("Window1")
window.geometry("300x300")
window.configure(background='grey')
f = "C:\\Users\\Bob\\Documents\\Python\\bb.gif"
img = tk.PhotoImage(file = f)
panel = ttk.Label(window, width= 100, background = "green", image =img)
panel.grid(column=1, row=1, sticky=(tk.W,tk.E))
picture()
window.mainloop()
In the above code, Why does the picture display in window1 but not window2? It works if the image is passed as a parameter to the function! running with Python3.