Cannot display image using python in anaconda jupyter notebook

Viewed 180

Despite trying multiple solution i could find on here. It seems like the image still fail to show. Any one could kindly shed some light on this would be greatly appreciated.

I'm using anaconda Jupiter notebook The current python version is 3.7.3

import tkinter as tk
import os
window = tk.Tk()
window.title("Test")
load = Image.open(r'C:\t.jpg')
render = ImageTk.PhotoImage(load)  
window.mainloop()

enter image description here

1 Answers

Okay, I see your issue now. PhotoImage loads the image into memory, but doesn't draw it.

Try putting this before window.mainloop():

    . . .
render = ImageTk.PhotoImage(load)
canvas = new Canvas(window, width=500, height=500) # Change the height and width to suit your image
canvas.pack() # Put the canvas on the window
canvas.create_image(0, 0, anchor=NW, image=render) # Put the image on the canvas
Related