I made a program with a genetic algorithm using pyevolve; it modifies a PIL Image every generation. The code is as follows.
def update_image():
global image
# Update image
...
ga = GSimpleGA.GSimpleGA( genome )
...
ga.stepCallback.set( update_image )
ga.evolve( freq_stats = 1 )
It works nice, but I can't see how the image changes; I can only see the final image when I save it to a file.
I tried using Tkinter and modified my program like this
root = Tk.Tk()
label = Tk.Label( root )
label.pack()
def update_image():
global image
# Update image
tkimage = ImageTk.PhotoImage( image )
label.configure( image = tkimage )
label.image = tkimage
...
ga = GSimpleGA.GSimpleGA( genome )
...
ga.stepCallback.set( update_image )
root.after( 1000, lambda : ga.evolve( freq_stats = 1 ) )
root.mainloop()
but it only runs the genetic algorithm and doesn't update the image.
Is there any other (easier) way to display an image and update it exactly when I need (with Tkinter or another library)?