Answer the question
In order to leave comments, you need to log in
How to insert image into canvas using pil and tkinter in python 3.5.1?
You need to load an image into the canvas. What am I doing wrong?
from tkinter import *
from PIL import *
from PIL import Image #если убрать эту строку, то выскочит еще одна ошибка
top = Tk()
canvas = Canvas()
canvas.pack()
img=Image.open("example.png") #для формата png подключил PIL
canvas.create_image(0,0, image=img) #основная ошибка, как я понял, здесь
label=Label(image=img)
label.pack()
top.mainloop()
Traceback (most recent call last):
File "C:\Users\Pogremix\AppData\Local\Programs\Python\Python35-32\MyExperiments\1.py", line 11, in
canvas.create_image(0,0, image= img)
File "C:\Users\Pogremix\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2328, in create_image
return self._create('image', args, kw)
File "C:\Users\Pogremix\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2319, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "" doesn't exist
Answer the question
In order to leave comments, you need to log in
Let's play find 10 differences? in your case
image "" doesn't exist
from Tkinter import *
import Image, ImageTk
root = Tk()
root.geometry('1000x1000')
canvas = Canvas(root,width=999,height=999)
canvas.pack()
pilImage = Image.open("ball.gif")
image = ImageTk.PhotoImage(pilImage)
imagesprite = canvas.create_image(400,400,image=image)
root.mainloop()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question