[Python] Python Tkinter Treeview add an image as a column value

Discussão em 'Python' iniciado por Stack, Agosto 21, 2025.

  1. Stack

    Stack Membro Participativo

    i'm trying to add an Image to the first column of every row on a treeview, but no matter what I do, always end up with the name of the object "pyimage1" showed instead of the actual image. As this image shows

    The code that i'm using is something like this.

    from tkinter import PhotoImage.
    self._img = PhotoImage(file="resources\information_picto.gif")
    self.tree.insert('', 'end', values= self._image,self.name, self.status, self.cores, self.turn, self.added_time)


    I've tried with png, with the same result, I know that my image object has been correctly created, because when debugging I can see the properties of the image, but I can't make it to show on the treeview row.

    Edit:

    def __init__(self, master, **kw):
    self.SortDir = True
    f = ttk.Frame(master)
    f.pack(fill=BOTH, expand=True)
    self.dataCols = ('Project Name', 'Status', 'Cores', 'Turn', 'Added date/time')
    self.tree = ttk.Treeview(columns=self.dataCols,
    show='headings')
    self.tree.column("Project Name", anchor="center")

    self.tree.grid(in_=f, row=0, column=0, sticky=NSEW)
    f.rowconfigure(0, weight=1)
    f.columnconfigure(0, weight=1)
    style = ttk.Style(master)
    style.configure('Treeview', rowheight=38)

    self._img = PhotoImage(file="resources\information_picto.gif")
    self.tree.insert('', 'end', text="#0's text", image=self._img,
    value=("A's value", "B's value"))


    I'm trying with the above code, it's pretty similar to yours, but i can't find my error, however I've watch that "text" nor "image" field appear on the row, just the list of values that i passed as "value", any thoughts?

    Continue reading...

Compartilhe esta Página