imagepython-3.xexportzelle-graphics

Export the contents of a GraphWin to an image file


Is there any chance I can save 'image' created in GraphWin to file? It does not matter what type, I just need to store it for later comparsion.

win = GraphWin("Test image", 500, 500)
c = Circle(Point(Items[i].x, Items[i].y), Items[i].z)
c.setFill(color)
c.draw(win)

Solution

  • Yes, since GraphWin is a subclass of Tkinter Canvas, you can do:

    from graphics import *
    
    win = GraphWin("Test image", 500, 500)
    c = Circle(Point(100, 100), 50)
    c.setFill("green")
    c.draw(win)
    
    win.postscript(file = "graphic.eps")