我想更改數據,只是將某些像素切換爲白色或黑色,但我沒有得到它的工作,我可以更改數據?當我使用行np.roll()時,它會滾動圖像並更新它,但是當我使用任何其他方法簡單地更改數據數組的值時,我失敗了?Tkinter更改數據
我該怎麼做,我錯了什麼?
import Tkinter
from PIL import Image, ImageTk
import numpy
import time
times=1
timestart=time.clock()
data=numpy.array(numpy.random.random((68,68))*100,dtype=int)
#data = numpy.zeros([68,68])
photo = None
sw = 1
def image_loop():
global data
global times
global timestart
global photo
im=Image.fromstring('L', (data.shape[1],data.shape[0]), data.astype('b').tostring())
photo = ImageTk.PhotoImage(image=im)
canvas.create_image(0,0,image=photo,anchor=Tkinter.NW)
root.update()
times+=1
if times%33==0:
print "%.02f FPS"%(times/(time.clock()-timestart))
root.after(100,image_loop)
### THE next line WORKS, why not the others ???????
#data=numpy.roll(data,-1,1)
### Does not work ??
global sw
if sw == 0:
for i in range(68):
data[10][i] * 100
#data = numpy.array(numpy.zeros(68,68))
sw = 1
print "hi"
else:
sw = 0
for i in range(68):
data[10][i]/100
data = numpy.array(numpy.ones(68,68))
#data = data * 100
print "ho"
root = Tkinter.Tk()
frame = Tkinter.Frame(root, width=68, height=68)
frame.pack()
canvas = Tkinter.Canvas(frame, width=68,height=68)
canvas.place(x=-2,y=-2)
root.after(0,image_loop) # INCREASE THE 0 TO SLOW IT DOWN
#root.mainloop()
while True:
print "do work again and again, change data"
root.update()
root.update_idletasks()
print data.shape
爲什麼我在這裏投票? –