[Tkinter-discuss] Generating Postscript from canvas whilst hidden

Igor Novikov igor.e.novikov at gmail.com
Wed Mar 2 02:15:34 CET 2011


You can try using pycairo to generate PS/PDF/PNG in the background.

http://cairographics.org/pycairo/
http://www.tortall.net/mu/wiki/CairoTutorial

I think this will be better way than widget tricks.

-- 
Regards,

Igor Novikov
sK1 Project
http://sk1project.org


On Tue, Mar 1, 2011 at 6:05 PM, Matt Keenan <matt.keenan at oracle.com> wrote:

> Hi,
>
> Looking for the best means of generating postscript from a canvas widget
> but having the canvas widget in the background, and not visible to the user.
>
> I have an application that I'd like to batch generate a web site from,
> including a set of graphs.
>
> the graphs are plotted on a canvas widget with a convenience function and
> then postscript is generated using the canvas.postscript() method.
>
> The only means I can see of generating valid postscript is when the canvas
> widget and root are displayed to the user. I'd prefer if this could be
> hidden.
>
> Following code is a rough example of what happens when the user clicks the
> generate button
>
>   def generate_webpage(self, emplist):
>       myroot = Tk()
>       mycanvas = Canvas(myroot, width=700, height=400)
>       mycanvas.pack()
>       mycanvas.root = myroot
>
>       for i in range(0, len(emplist)):
>           # PostScript file name
>           psname = "graph%s.ps" % (i)
>
>           # Clear canvas down
>           canvas.delete(ALL)
>
>           # Plot graph on canvas
>           PlotLineGraph(mycanvas, emplist[i])
>
>           # Update tasks and canvas
>           self.update_idletasks()
>           mycanvas.update()
>           mycanvas.update_idletasks()
>
>           # Generate postscript
>           mycanvas.postscript(file=psname, pagewidth=675,
>               pageheight=400)
>
>       myroot.destroy()
>
>
> As can be seen, when generate_webpage is clicked, a new popup window is
> shown and each graph as generated is shown within the window as it's done.
>
> If I add myroot.withdraw() to above method, just after packing mycanvas,
> then no popup appears but all the postsript files are blank
> nothing is actually plotted on the canvas !!
>
> Does anyone know of a way to get around this ?
>
> cheers
>
> Matt
>
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20110302/5e3d8168/attachment.html>


More information about the Tkinter-discuss mailing list