from PIL import Image,ImageTk from math import * from commands import getoutput from Tkinter import Tk,Canvas layer_thickness = 7.5 contents = ["../B1run02_png/" + i for i in getoutput("ls ../B1run02_png/").split()] stack = [Image.open(fn) for fn in contents] #im = Image.open("/home/seth/B1run02_png/B1_Run02_BSED_slice_0176.png") width, height = stack[0].size print width, height # # pix = im.load() # current_image = 0 app = Tk() canvas = Canvas(app) canvas.pack() canvas['width'] = 1280 canvas['height'] = 960 pimg = ImageTk.PhotoImage(image=stack[0]) canvas.create_image(0, 0, anchor='center', image=pimg) def changeimages(event, direction=1): global pimg, current_image current_image += direction if(current_image >= len(stack)): current_image = 0 if(current_image < 0): current_image = len(stack)-1 pimg = ImageTk.PhotoImage(image=stack[current_image]) canvas.create_image(0, 0, anchor='nw', image=pimg) canvas.bind("", changeimages) canvas.bind("", lambda e : changeimages(e, -1)) sideways = Image.new("L", (int(len(stack) * layer_thickness), stack[0].size[1])) pix = sideways.load() for z in range(sideways.size[0]): spix = stack[int(z/layer_thickness)].load() for y in range(sideways.size[1]): pix[z,y] = spix[0,y] pimg = ImageTk.PhotoImage(image=sideways) canvas.create_image(0, 0, anchor='nw', image=pimg) app.mainloop()