I want to create an png format image in Tkinter text widget

126 Views Asked by At

I want to create an png format image in Tkinter text widget. when I run my code, it works but just show a white image. what can I do about that?

elif int(w4_toc1.selection()[0]) == 21:
w4_tex_title.insert('end', doc.paragraphs[57].text)
w4_tex_title.insert('end', '\n'+'\n'+'\n'+doc.paragraphs[58].text)
for i in range(59,62):
    w4_testrong textx_title.insert('end', '\n'+'\n'+doc.paragraphs[i].text)`enter code here`
from PIL import Image,ImageTk
dimension_table = Image.open('icons\coordinate.png')
dt = ImageTk.PhotoImage(dimension_table)
w4_tex_title.image_create('end+2 lines',align=CENTER, image=dt)
1

There are 1 best solutions below

2
On

You need to keep reference to the image, or pythons garbage collector sweeps the image.

dt = ImageTk.PhotoImage(dimension_table)
w4_tex_title.image = dt #Keeping Reference to the Image
w4_tex_title.image_create('end+2 lines',align=CENTER, image=dt)