我查找了这个问题,发现了几个线程,但我使用了相同的公式,对我的问题无济于事。我有三列,我想在第一列插入一张图像。我想做的比这更复杂,但我认为我应该尽可能简单地展示我遇到的问题。下面是我的代码:
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
root = Tk()
tree = ttk.Treeview( root , column=("c1","c2","c3") , show='headings' , height = 10 , )
tree.pack( side = LEFT, fill = BOTH )
scrollbar_tree_select_movie = Scrollbar( root )
scrollbar_tree_select_movie.pack(side = RIGHT, fill = BOTH )
tree.config(yscrollcommand = scrollbar_tree_select_movie.set)
scrollbar_tree_select_movie.config(command = tree.yview)
tree.heading("#1", text="Icon" )
tree.column("#1", anchor= CENTER , width = 50 )
tree.heading("#2", text="Name" )
tree.column("#2", anchor= CENTER , width = 300 )
tree.heading("#3", text="Year" )
tree.column("#3", anchor= CENTER , width = 50 )
img = ImageTk.PhotoImage( Image.open("the-matrix-movie-poster-xs.png") )
tree.insert('',END,values=('','The Matrix','1999'), image=img )
root.mainloop()
看起来我的问题是show = 'headings'
选项。删除后,图像显示。