Displaying images with Tkinter
Back
To display images, you need a graphics library, such as Tk, wxWindows, or Qt. See the Graphic User Interface FAQ for more information. 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
im.convert2byte()
which is a method of SPIDER files that have been opened in Image..
import Tkinter
import Image, ImageTk
im = Image.open('slice001.hrs').convert2byte()
root = Tkinter.Tk()
tkimage = ImageTk.PhotoImage(im)
Tkinter.Label(root, image=tkimage).pack()
root.mainloop()
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.