Listing 3. Saving a PostScript Image, Then Exiting

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.Tk import *
import sys

def display(togl):
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
   glColor3f(0.3, 1.0, 1.0)
   glMaterialfv(GL_FRONT, GL_AMBIENT,
   [0.1745, 0.0, 0.1, 0.0])
   glMaterialfv(GL_FRONT, GL_DIFFUSE,
   [0.1, 0.0, 0.6, 0.0])
   glMaterialfv(GL_FRONT, GL_SPECULAR,
   [0.7, 0.6, 0.8, 0.0])
   glMaterialf(GL_FRONT, GL_SHININESS, 80)
   glutSolidTeapot(1.0)
   glFlush()
   openglutil.glSaveEPS('teapot.eps', 240, 240)
   sys.exit()

togl = Opengl(width = 250, height = 250, double = 1)
togl.redraw  = display
togl.pack(side = 'top', expand = 1, fill = 'both')
togl.basic_lighting()
togl.set_background(0, 0, 0)
togl.mainloop()