1

When I try to insert the image into my Tkinter window all that shows up is this

import tkinter as tk
root = tk.Tk()
root.title("To Do List")
canvas = tk.Canvas(root, height=900, width=1000, bg='white')
frame = tk.Frame(root, bg="#000000")
img = tk.PhotoImage("deathnote.png")
entry = tk.Entry(frame, font='system', fg='white', bg='black')
imglabel = tk.Label(frame, image=img)
canvas.grid(row=0, column=0)
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
imglabel.grid(row=0, column=2)
entry.grid(row=1, column=1)


root.mainloop()
1
  • Should be img = tk.PhotoImage(file="deathnote.png"). Commented Apr 1, 2020 at 2:12

1 Answer 1

2

Try using PIL:

import tkinter as tk
from PIL import ImageTk, Image

root = tk.Tk()
root.title("To Do List")
canvas = tk.Canvas(root, height=900, width=1000, bg='white')
frame = tk.Frame(root, bg="#000000")
img = ImageTk.PhotoImage(Image.open("deathnote.png"))
entry = tk.Entry(frame, font='system', fg='white', bg='black')
imglabel = tk.Label(frame, image=img)
canvas.grid(row=0, column=0)
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
imglabel.grid(row=0, column=2)
entry.grid(row=1, column=1)


root.mainloop()
Sign up to request clarification or add additional context in comments.

4 Comments

I was doing that previously and it says "_tkinter.TclError: couldn't recognize data in image file "deathnote.png"
Weird. that works for me. I just updated my answer. Look up and try it
If it matters I'm using Pycharm to do this. when I try to import PIL it doesn't recognize it and when I try to install it the error message is "Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL"
Do not install "PIL". You have to install Pillow: pip3 install Pillow if you are using python 3 or pip install Pillow if you are using python 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.