How to open PIL Image in Tkinter on Canvas

后端 未结 4 1157
面向向阳花
面向向阳花 2021-02-14 18:08

I can\'t seem to get my PIL Image to work on canvas. Code:

from Tkinter import*
import Image, ImageTk
root = Tk()
root.geometry(\'1000x1000\')
canvas = Canvas(ro         


        
4条回答
  •  面向向阳花
    2021-02-14 18:26

    Try creating a PIL Image first, then using that to create the PhotoImage.

    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()
    

提交回复
热议问题