У меня проблема при добавлении одного изображения в древовидную структуру из def
случай один - все в порядке
import tkinter
import PIL.Image, PIL.ImageTk
from tkinter import PhotoImage
from tkinter import ttk
window = tkinter.Tk()
tree = ttk.Treeview(window)
tree["columns"]="one"
tree.heading("#0",text="Item",anchor=tkinter.W)
tree.heading("one", text="Detections",anchor=tkinter.W)
style = ttk.Style(window)
style.configure('Treeview', rowheight=50)
tree.grid(row=0,column=0,sticky=tkinter.N)
img = PIL.Image.open("1.jpg")
img = img.resize((10, 10))
img = PIL.ImageTk.PhotoImage(img)
tree.insert('', 'end', text="predict", image=img, value=("title"))
случай два - не работает
window = tkinter.Tk()
tree = ttk.Treeview(window)
tree["columns"]="one"
tree.heading("#0",text="Item",anchor=tkinter.W)
tree.heading("one", text="Detections",anchor=tkinter.W)
style = ttk.Style(window)
style.configure('Treeview', rowheight=50)
tree.grid(row=0,column=0,sticky=tkinter.N)
#img = PIL.Image.open("2.jpg")
#img = img.resize((10, 10))
#img = PIL.ImageTk.PhotoImage(img)
#tree.insert('', 'end', text="predict", image=img, value=("title"))
def snapshot():
img = PIL.Image.open("2.jpg")
img = img.resize((10, 10))
img = PIL.ImageTk.PhotoImage(img)
tree.insert('', 'end', text="predict2", image=img, value=("title2"))
btn_snapshot=tkinter.Button(window, text="Snapshot", width=50, command=snapshot)
btn_snapshot.grid(row=1,column=0)
Тогда проблема в том, что при добавлении изображения из def .... я могу добавить элемент, но изображение не видно
Есть идеи?