Rendering a canvas into a PostScript file
The Canvas
class natively supports saving its contents using the PostScript language via its postscript()
method. This stores the graphical representation of canvas items, such as lines, rectangles, polygons, ovals, and arcs, however, it does not do so for embedded widgets and images.
We will modify a previous recipe that dynamically generates this type of simple items to add the functionality to save a representation of the canvas into a PostScript file.
How to do it...
We will take the code sample from the Drawing lines and arrows recipe to add a button to print the canvas contents to a PostScript file:
import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.title("Basic canvas") self.line_start = None self.form = LineForm(self) self.render_btn = tk.Button(self, text="Render canvas", command=self.render_canvas) self.canvas = tk.Canvas...