Non riesco a far funzionare la mia immagine PIL su tela. Codice:Come aprire l'immagine PIL in Tkinter su tela
from Tkinter import*
import Image, ImageTk
root = Tk()
root.geometry('1000x1000')
canvas = Canvas(root,width=999,height=999)
canvas.pack()
image = ImageTk.PhotoImage("ball.gif")
imagesprite = canvas.create_image(400,400,image=image)
root.mainloop()
Errore:
Traceback (most recent call last):
File "C:/Users/Mark Malkin/Desktop/3d Graphics Testing/afdds.py", line 7, in <module>
image = ImageTk.PhotoImage("ball.gif")
File "C:\Python27\lib\site-packages\PIL\ImageTk.py", line 109, in __init__
mode = Image.getmodebase(mode)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 245, in getmodebase
return ImageMode.getmode(mode).basemode
File "C:\Python27\lib\site-packages\PIL\ImageMode.py", line 50, in getmode
return _modes[mode]
KeyError: 'ball.gif'
ho bisogno di usare le immagini non pil PhotoImages perché voglio ridimensionare le mie immagini. Per favore non suggerire di passare a Pygame perché voglio usare Tkinter.
Sono confuso - dici di non voler usare 'PhotoImage's, ma il tuo codice usa un' PhotoImage'. Vuoi dire che vuoi usare 'ImageTk.PhotoImage' piuttosto che' Tkinter.PhotoImage'? – Brionius
Hai provato a leggere i documenti per 'PhotoImage'? Prende un oggetto immagine, o una modalità e una dimensione. Non lo passi neanche; stai passando un nome di file. (Il 'KeyError' su' return _modes [mode] 'rende abbastanza ovvio che sta cercando di trattare il nomefile come una modalità ... ma non importa quale abbia provato, fallirebbe in entrambi i modi.) – abarnert