使用TKinter Canvas动画PIL图像

时间:2013-05-30 03:53:28

标签: canvas tkinter python-imaging-library

以下是将PIL图像放在TKinter画布上的代码。如何让它一次添加一个像素而不是一次添加整个图像?

#!/usr/bin/python
from Tkinter import *
import Image, ImageDraw, ImageTk
import profile
import re

W = 455
H = 328
img = Image.new("RGB", (W, H), "black")
draw = ImageDraw.Draw(img)


for x in range(W):
     for y in range(H):
        color = (x % 255, y % 255, (x % (y+1)) % 255)
        draw.point((x,y), fill=color)
img.save("img.png", "PNG")


root=Tk() 
frame=Frame(root,width=900,height=630) 
frame.grid(row=0,column=0) 
canvas=Canvas(frame,bg='#FFFFFF',width=930,height=600) 
canvas.pack(side=LEFT,expand=True,fill=BOTH) 
imgtk = ImageTk.PhotoImage(img)
item=canvas.create_image(100,100,anchor=NW,image=imgtk)
mainloop()

0 个答案:

没有答案