Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Image does not show in treeview.
#1
I'm trying to put images into treeviews.

Why does the image file Part.png not show up in this treeview.

I've loaded the same image ( Part.png) to show in the window and that works OK. are there some prerequisites for images on treeviews?



    tupbomi = [tuple(row) for row in all_rows]

    # How may items in this BOM
    print(len(tupbomi))
    numbomi = (len(tupbomi))

    for nbi in range(0,(numbomi)):
        tupbomd=tupbomi[nbi]
        print(( str(nbi)) + ' ' + tupbomd[1] + ' ' + tupbomd[2] + ' ' + tupbomd[3])

        img = tk.PhotoImage(file='resources/Part.png')
                # Check that image and path are correct by displaying on window
        window.tk.call('wm', 'iconphoto', window._w, PhotoImage(file='resources/Part.png'))
                # OK image shows

        # This will be BOM
        if tupbomd[2]== 'D':
            nbi= tree1.insert("", nbi, str(nbi), text=tupbomd[3], image=img , values=(tupbomd[2], tupbomd[3], tupbomd[4]))
            tree1.insert(nbi, "end", str(nbi)+'.1', text=tupbomd[3], image=img , values=(tupbomd[2], tupbomd[3], tupbomd[4]))

        # This will be a part
        else:
            tree1.insert("", nbi, text=tupbomd[3], image=img, values=( tupbomd[2], tupbomd[3], tupbomd[4]))
Quote
#2
Can you give some context? Is there a library you're using? Is this a GUI question or a non-GUI question?
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#3
Context: I'm searching for matching records from an SQLite database.


the tuple tupbomi contains the fetchall results from that database.

Where the record tupbomd[2]== 'D': this is a node with further detail to be expanded.



Not a GUI question, however I suppose that in doing this I am writing my own window user interface (GUI).

I should say that in future the appropriate image will be identified by tupbomd[n], in the first instance I just want to understand how to load an image into a treeview.
Quote
#4
While the following code is inside the function it will at least provide an image for the last item on the list. If the code is outside the function it provides the same image for all items in the treeview.

At runtime I want to do is read the required image for example tupbomd[n] and apply the appropriately rendered image to that particular line of the treeview.



 

        widt = 16
        hght = 16
        img = Image.open('resources/Part.png')
        img = img.resize((widt, hght), Image.ANTIALIAS)
        render = ImageTk.PhotoImage(img)
    for nbi in range(0,(numbomi)):

        tupbomd=tupbomi[nbi]

        widt = 16
        hght = 16
        img = Image.open('resources/Part.png')
        img = img.resize((widt, hght), Image.ANTIALIAS)
        render = ImageTk.PhotoImage(img)

        # This will be BOM
        if tupbomd[2]=='D':
            drgnumb = tupbomd[3]
            bom_read_drawing()
            nbi= tree1.insert("", nbi, str(nbi), text=tupbomd[3], image=render, values=(tupbomd[2], tupbomd[3], tupbomd[4] ,des1))
            tree1.insert(nbi, "end", str(nbi)+'.1', text=tupbomd[3], image=render, values=(tupbomd[2], tupbomd[3], tupbomd[4]))

        # This will be a part
        else:
            partnum = tupbomd[3]
            bom_read_part()
            tree1.insert("", nbi, text=tupbomd[3], image=render, values=(tupbomd[2], tupbomd[3], tupbomd[4],des1))


    conn.close()
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyQt] How to populate a treeview on a GUI with a dictionary mart79 1 362 Aug-05-2019, 01:30 PM
Last Post: Denni
  [Tkinter] Not getting entry values on button click & treeview not updating ? swanysto 4 785 May-10-2019, 04:16 PM
Last Post: swanysto
  [Tkinter] Tkinter timetabl using treeview mntfr 3 382 Feb-05-2019, 09:36 PM
Last Post: Larz60+
  [Tkinter] I need to know how to put my SQLite3 data into a Treeview Thename921 1 1,072 Jan-12-2019, 10:26 PM
Last Post: Larz60+
  bind hover on tkinter.ttk.Treeview Larz60+ 4 5,953 May-20-2017, 10:28 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)