Displaying images with Tkinter


To display images, you need a graphics library, such as Tk, wxWindows, or Qt. Tkinter is the Python interface to the Tk library, included with the Python distribution.
The Tkinter Manual
Tkinter documentation and links

The example below uses the Python Imaging Library (PIL) to read SPIDER images into Python, and the ImageTk module from PIL to paste photos into the Tkinter graphics display.

SPIDER images must be converted to byte format before they can be converted to Tk.PhotoImages. The standard PIL method for converting to byte format,
new = im.convert('L')
often fails for very small floating point numbers, so it is better to use
which is a method of SPIDER files that have been opened in Image.
# import Image and the graphics package Tkinter
import Tkinter 
import Image, ImageTk

# open a SPIDER image and convert to byte
im = Image.open('slice001.hrs').convert2byte()

root = Tkinter.Tk()  
# A root window for displaying objects

 # Convert the Image object into a TkPhoto 
tkimage = ImageTk.PhotoImage(im)

Tkinter.Label(root, image=tkimage).pack() 
# Put it in the display window

root.mainloop() # Start the GUI

Code for a simple SPIDER image viewer

GUI for displaying a sequence of images

GUI for displaying a images in a SPIDER stack

For more elaborate examples, see the Graphical tools supplied with Spire.