Tkinter Treeview Insert Image
If you add the image parameter within the insert( ) method you can add an image. What you need to consider when adding an image is that the height of the row may be insufficient, so you must increase the height. This can be handled with the following Style( ) method.
Style().configure("TreeView", rowHeight=xx) # xx is the height setting
Example#1
Design a Treeview with images.
from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
root = Tk()
root.title("apidemos.com")
Style().configure("Treeview",rowheight=35) # Formatted expansion row height
info = ["The Phoenix News App provides access to the latest news from around China",
"Swiss National Rail App provides all Swiss train schedules",
"Coca-Cola App is a software for entertainment"]
tree = Treeview(root,columns=("Description"))
tree.heading("#0",text="App") # Icon bar
tree.heading("#1",text="Function Description")
tree.column("#1",width=300) # Formatting column headings
img1 = Image.open("apidemos.png") # Insert apidemos.png
imgObj1 = ImageTk.PhotoImage(img1)
tree.insert("",index=END,text="Phoenix News",image=imgObj1,values=info[0])
img2 = Image.open("apidemos.png") # Insert apidemos.png
imgObj2 = ImageTk.PhotoImage(img2)
tree.insert("",index=END,text="Swiss Railways",image=imgObj2,values=info[1])
img3 = Image.open("apidemos.png") # Insert apidemos.png
imgObj3 = ImageTk.PhotoImage(img3)
tree.insert("",index=END,text="Coca-Cola",image=imgObj3,values=info[2])
tree.pack()
root.mainloop()
Output: