I am trying to get an image to display in a tkinter canvas.
I know the Canvas
works with shapes and text, but image isn't working.
I am using PIL
ImageTK.PhotoImage
, however it also doesn't work creating a Tkinter.PhotoImage
using a '.ppm' image.
The 'png'
image is stored in the same directory as the python file.
import tkinter as tk
from PIL import Image, ImageTk
class Window:
def __init__(self):
self.window = tk.Tk()
self.window.title("COMP")
self.window.geometry("1200x600")
topframe = tk.Frame(self.window, highlightbackground='black', highlightthickness=1)
topframe.pack(side='top')
self.noteview = NoteView(topframe, self.songString)
class NoteView:
def __init__(self, frame):
self.canvas = tk.Canvas(frame, width=60, height=200)
self.canvas.pack()
self.canvas.create_text(15, 190, text='hi')
im = Image.open('png.png')
self.image = ImageTk.PhotoImage(im)
self.canvas.create_image(20, 20, anchor='nw', image=self.image)
w = Window()
TypeError: 'PhotoImage' object is not callable