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?
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
  [Tkinter] How to get the result of a ping to show in tkinter? jacklee26 5 304 Jun-15-2019, 08:50 PM
Last Post: Yoriz
  [Tkinter] Please help, my Label does not show up on my gui ? robertinoc 2 190 Jun-12-2019, 05:58 PM
Last Post: robertinoc
  [Tkinter] Not getting entry values on button click & treeview not updating ? swanysto 4 370 May-10-2019, 04:16 PM
Last Post: swanysto
  [WxPython] How to show remove button at the right side of the hovering item of a combobox popup? indrajitmajumdar 0 189 Mar-28-2019, 11:24 AM
Last Post: indrajitmajumdar
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 216 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  How to show graph as a slideshow in PyQt5 using matplotlib binsha 0 495 Mar-08-2019, 03:58 AM
Last Post: binsha
  [Tkinter] Tkinter timetabl using treeview mntfr 3 260 Feb-05-2019, 09:36 PM
Last Post: Larz60+
  Why QListWidget doesn't show new line? AlekseyPython 3 326 Feb-05-2019, 02:23 PM
Last Post: AlekseyPython
  sQlite3 output to tkinter treeview - how do I set / increase width of the output? dewijones67 5 571 Jan-23-2019, 08:45 AM
Last Post: Larz60+
  [Tkinter] I need to know how to put my SQLite3 data into a Treeview Thename921 1 662 Jan-12-2019, 10:26 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)