title: Python - Tkinter saved PS images - can't open them
body: <p>I have written a pretty convoluted script for creating graphics - via the Tkinter module. </p>
  
  <p>It works as I expect, and saves the canvas as a PostScript file. </p>
  
  <p>Only, I can't render the PS file in anything. At all. </p>
  
  <p>I was pretty confident when I decided to use Tkinter that there would be something I could do with the PS files to get them into some more standard format. </p>
  
  <p>I have seen some tutorials that suggest porting the drawings to PIL, which might work, but will be quite a task to port all the dynamic objects from tk to PIL. </p>
  
  <p>I wondered if anyone had a quicker/dirtier way of getting the pixels off the widget window into an image file. </p>
  
  <p>Or any windows methods of viewing/rasterising the PS file? I can place an example PS file somewhere if there is interest? (the python code is quite involved, and requires 3 MySQL tables to pull the data together)</p>
  
  <p>I am trying to use the screengrab method from here: <a href="http://mail.python.org/pipermail/image-sig/2003-May/002292.html" rel="nofollow">http://mail.python.org/pipermail/image-sig/2003-May/002292.html</a></p>
  
  <p>and and struggle to get things in the right order. </p>
  
  <p>tkinter code: </p>
  
  <pre><code>def drawCircles(MasterList,buildlist):
  master = Tk()
  w = Canvas(master, width=1000, height=1000)
  w.config(bg='white')
  coordsMain = MasterList[6:]
  textMain = MasterList[0:2]
  w.pack()
  w.create_oval(*coordsMain, width=3, fill = "ivory3")
  masterLabel = "Source PUID\n" + str(MasterList[3]) + "\nFiles = " + str(MasterList[4])
  w.create_text(*textMain, text=masterLabel, justify = "center", font=("Helvetica", 16))
  for i in buildlist:
   coordsSet = i[6:10]
   w.create_oval(*coordsSet, width=3, fill = i[5])
   set_label = i[3] + "\n" + str(i[4]) + "%"
   l=w.create_text(4,4, text=set_label, justify = "center", fill="white", font=("Helvetica", 16))
   a,b,c,d= (w.bbox(l))
   bboxArea =(c-a)*(d-b)   
   a,b,c,d = i[6:10]
   circleArea = (c-a)*(d-b)
   if bboxArea&gt;circleArea:
    textSet = i[10:]
    j=w.create_text(*textSet, text=set_label, justify = "center", font=("Helvetica", 16))
    r=w.create_rectangle(w.bbox(j),fill="white", width=0)
   else:
    textSet = i[:2]
    j=w.create_text(*textSet, text=set_label, justify = "center", font=("Helvetica", 16))
    r=w.create_rectangle(w.bbox(j),fill=i[5], width=0) 
   w.tag_lower(r,j)
   PUID = str(MasterList[3])
   PUID = PUID.replace('/', '-')
   filename = "\images\\" + PUID + ".jpg"
  mainloop()
  </code></pre>
  
  <p>Screen grab code:</p>
  
  <pre><code>x0 =w.winfo_rootx()
  y0 =w.winfo_rooty()
  x1 =x0 + w.winfo_width()
  y1 =y0 + w.winfo_height()
  im =ImageGrab.grab((x0, y0, x1, y1))
  im.save(filename)
  </code></pre>
  
  <p>I can make a jpg this way, but can't seem to get the contents of the widget in the the jgp (the file that gets created declares as a jpg, but has no image payload)</p>
  
  <p>If I place the screen grab code after the mainloop, it has says its destroyed the object, before mainloop, its not built the object yet.... </p>